iphone - 计算 NSDictionary 中的 allKeys 返回 EXC_BAD_ACCESS

标签 iphone ios count nsdictionary

我正在尝试将 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];
}
}

如果我像这样使用 allKeys:

NSLog([[dict objectForKey:@"Room"] allKeys]);

它在控制台中返回 ("Item 1", "Item 2")。

但是当我像这样添加“计数”方法时:

NSLog(@"%@", [[[dict objectForKey:@"Room"] allKeys] count]);

我刚刚得到:程序收到信号:“EXC_BAD_ACCESS”。

我在这里错过了什么?

最佳答案

NSLog(@"%@", [[[dict objectForKey:@"Room"] allKeys] count]);

count 给出了一个 int,但是你用 %@ 打印,期望一个指向对象的指针。请改用 %d

关于iphone - 计算 NSDictionary 中的 allKeys 返回 EXC_BAD_ACCESS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4540848/

相关文章:

google-sheets - 忽略隐藏列的公式

iphone - iOS 7 下 UITableView 部分索引相关的崩溃

ios - 如何在 ios 中根据图像动态更改 UI 按钮的宽度和高度

ios - 向后导航时相机进给卡住 - ios,objective-c

ios - 如何让 iOS 应用程序在 iPhone 5、iPhone 6 和 iPhone 6+ 上看起来一样

php - 将计数添加到 SQL 查询

mysql - HQL:where 子句中的未知列

iphone - 如何从MKMapView中的kml文件获取地标图标?

ios - 图像是否会在 iOS 更新时从本地文件系统中删除?

ios - 上传高分 - 如何让它只对 friend 可见?