如何使用 NSMutableArray 准备 ForSegue?
NSMutableArray *theNews;
这是prepareForSegue代码
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"showDetail"]) {
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
NSManagedObject *object = [[theNews objectAtIndex:indexPath.row] objectAtIndexPath:indexPath];
[[segue destinationViewController] setDetailItem:object];
}
}
如果我运行代码我得到这个错误:
由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[__NSDictionaryM objectAtIndexPath:]:无法识别的选择器发送到实例 0x81c0f40”
最佳答案
您的theNews
数组中的数据似乎有点像NSDictionary
。没有名为 - objectAtIndexPath:
和 NSDictionary
的方法。您应该改用 – objectForKey:
(或其他一些方法)
关于iphone - 如何使用 NSMutableArray prepareForSegue?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14773377/