kro*_*ofy 4 iphone count nsdictionary ios
我正在尝试将NSDictionary发送到TableViewController,数据最初来自.plist文件.我只想将层次结构中存在的对象发送到新的TableViewController.但是当我尝试计算numberOfSectionsInTableView中的项目数时会出现问题.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// Gets the dictionary for the currently selected row
NSDictionary *dict = [[data objectForKey:[[data allKeys] objectAtIndex:indexPath.section]] objectAtIndex:indexPath.row];
// Checks if the key "Room" exists
if([dict objectForKey:@"Room"]) {
SalesFairSessionTableViewController *sessionViewController = [[SalesFairSessionTableViewController alloc] init];
// Sets the data in the subview Controller
[sessionViewController setData:[dict objectForKey:@"Room"]];
// And the title
[sessionViewController setTitle:[dict objectForKey:@"Title"]];
// Problem is here... returns EXC_BAD_ACCESS
NSLog(@"%@", [[[dict objectForKey:@"Room"] allKeys] count]);
[self.navigationController pushViewController:sessionViewController animated:YES];
[sessionViewController release];
}
}
Run Code Online (Sandbox Code Playgroud)
如果我只是使用allKeys:
NSLog([[dict objectForKey:@"Room"] allKeys]);
Run Code Online (Sandbox Code Playgroud)
它在控制台中返回("Item 1","Item 2").
但是,当我添加这样的"计数"方法时:
NSLog(@"%@", [[[dict objectForKey:@"Room"] allKeys] count]);
Run Code Online (Sandbox Code Playgroud)
我得到:程序接收信号:"EXC_BAD_ACCESS".
我在这里错过了什么?
Eik*_*iko 10
NSLog(@"%@", [[[dict objectForKey:@"Room"] allKeys] count]);
Run Code Online (Sandbox Code Playgroud)
count给出一个int,但你打印时%@,期望指向一个对象的指针.请%d改用.