Iphone 从nsdictionary分配给nsarray的指针类型不兼容
我是iPhone开发的新手,在这里的答案方面取得了巨大的成功,所以我希望能直接得到帮助。我正在从plist将数据读入tableview。该应用程序运行良好,但在编译时收到2条警告。我知道为什么会出现错误,但我在解决问题方面一直没有成功。虽然这个应用程序的工作,我真的想有效地解决警告。当我尝试将NSDictionary更改为NSArray时,警告消失,但不再填充该表 任何帮助都将不胜感激 人员和数据在Delegate.h文件中定义为NSArray。警告显示在下面的delegate.m文件中 我的代表有以下几点:Iphone 从nsdictionary分配给nsarray的指针类型不兼容,iphone,ios,xcode,nsarray,plist,Iphone,Ios,Xcode,Nsarray,Plist,我是iPhone开发的新手,在这里的答案方面取得了巨大的成功,所以我希望能直接得到帮助。我正在从plist将数据读入tableview。该应用程序运行良好,但在编译时收到2条警告。我知道为什么会出现错误,但我在解决问题方面一直没有成功。虽然这个应用程序的工作,我真的想有效地解决警告。当我尝试将NSDictionary更改为NSArray时,警告消失,但不再填充该表 任何帮助都将不胜感激 人员和数据在Delegate.h文件中定义为NSArray。警告显示在下面的delegate.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];
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;
在我的staff ViewController中,我有以下内容:
- (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];
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;
代码中的所有内容都表明人员和数据属性是NSDictionary实例。将它们初始化为字典对象,并将它们作为字典对象引用。为什么要将它们声明为NSArray对象 您应该更改它们的声明方式,以便它们在头文件中而不是NSArray中。在我看来,这是消除你的警告的最合乎逻辑的方法 假设“staff”NSDictionary的内容有一个名为“Rows”的键,其值为NSArray,则该方法仍然有效。您必须使用空NSArray初始化self.tableDataSource的代码似乎是多余的,因为您会立即使用
self.tableDataSource = [AppDelegate.staff valueForKey:@"Rows"];
代码中的行代码中的所有内容都表明人员和数据属性是NSDictionary实例。将它们初始化为字典对象,并将它们作为字典对象引用。为什么要将它们声明为NSArray对象 您应该更改它们的声明方式,以便它们在头文件中而不是NSArray中。在我看来,这是消除你的警告的最合乎逻辑的方法 假设“staff”NSDictionary的内容有一个名为“Rows”的键,其值为NSArray,则该方法仍然有效。您必须使用空NSArray初始化self.tableDataSource的代码似乎是多余的,因为您会立即使用
self.tableDataSource = [AppDelegate.staff valueForKey:@"Rows"];
代码中的行一个
NSArray
包含一个一维项目列表,其中NSDictionary
将键映射到值
数组:
[甲、乙、丙]
字典:
{@“a”=@“第一项”,“b”=@“第二项”}
能否将数据声明为NSDictionary*数据代码>并将其填充为数据=[[NSDictionary alloc]initWithContentsOfFile:DataPath]代码>
然后使用[data valueForKey:@“key”]
访问字典中的值NSArray
包含一个一维项目列表,其中NSDictionary
将键映射到值
数组:
[甲、乙、丙]
字典:
{@“a”=@“第一项”,“b”=@“第二项”}
能否将数据声明为NSDictionary*数据代码>并将其填充为数据=[[NSDictionary alloc]initWithContentsOfFile:DataPath]代码>
然后使用[data valueForKey:@“key”]
访问字典中的值,非常感谢。我以前试过这个,结果桌子空了,但是这次它成功了。非常感谢。我以前试过这个,但是这一次桌子空了。你解决了这个问题吗@科里·布朗我遇到了同样的问题你解决了吗@科里·布朗我遇到了同样的问题