2011-10-25 58 views
1

我是iPhone新手,并且从这里获得了很大的成功,因此我希望能够直接获得帮助。我正在将数据读入plist的tableview中。该应用程序工作正常,但我编译时得到2个警告。我知道为什么我会得到这些错误,但我一直没有解决问题。虽然这个应用程序的作品,我真的想有效解决警告。当我尝试将NSDictionary更改为NSArray时,警告消失,但表不再填充。从nsdictionary分配给nsarray的不兼容指针类型

任何帮助将不胜感激。

工作人员和数据在委托.h文件中定义为NSArray。警告显示在下面的代理.m文件中。

我的代表有以下几点:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    // Override point for customization after application launch. 
    // Add the tab bar controller's current view as a subview of the window 

NSString *Path = [[NSBundle mainBundle] bundlePath]; 
NSString *DataPath = [Path stringByAppendingPathComponent:@"Data.plist"]; 
NSString *SPath = [[NSBundle mainBundle] bundlePath]; 
NSString *StaffPath = [SPath stringByAppendingPathComponent:@"Staff.plist"]; 

NSDictionary *tempDict = [[NSDictionary alloc] initWithContentsOfFile:DataPath]; 
**self.data = tempDict;** 
[tempDict release]; 


    NSDictionary *staffDict = [[NSDictionary alloc]initWithContentsOfFile:StaffPath]; 
    **self.staff = staffDict;** 
    [staffDict release]; 

在我的工作人员的ViewController我有以下几点:在你的代码

if(CurrentLevel == 0) { 

     //Initialize our table data source 
     NSArray *staffDict = [[NSArray alloc] init]; 
     self.tableDataSource = staffDict; 
     [staffDict release]; 


     Midwest_DigestiveAppDelegate *AppDelegate = (Midwest_DigestiveAppDelegate *)[[UIApplication sharedApplication] delegate]; 
    self.tableDataSource = [AppDelegate.staff valueForKey:@"Rows"];  
} 
else 
    self.navigationItem.title = CurrentTitle; 
+0

你解决了这个问题吗? @Corey Brown我遇到同样的问题 –

回答

0

一切都表明,员工和数据属性的NSDictionary实例。您将它们初始化为字典对象,然后将它们作为字典对象引用。那么为什么你将它们声明为NSArray对象呢?

你应该改变它们是如何声明的,所以它们在你的头文件中是NSDictionary而不是NSArray。在我看来,这是删除警告最合乎逻辑的方法。

这应该仍然工作,假设你的“staff”NSDictionary的内容有一个名为“行”的键值为NSArray的键。你有一个空的NSArray初始化self.tableDataSource的代码似乎是多余的,因为你立即覆盖在你的代码与

self.tableDataSource = [AppDelegate.staff valueForKey:@"Rows"]; 

线值

+0

非常感谢。我之前尝试过这种方法,而桌子却是空的,但这次它工作正常。 –

1

NSArray持有的项目,其中的一个一个维列表NSDictionary将键映射到值。

阵列:

[A,B,C]

词典:

{@ “一”= @ “第一项”,@ “B”= @“第二项“}

你能申报数据为NSDictionary *data;和填充它为data = [[NSDictionary alloc] initWithContentsOfFile:DataPath];

然后在字典中访问值[data valueForKey:@"key"]

相关问题