【问题标题】:How to prepareForSegue using NSMutableArray?如何使用 NSMutableArray 准备 ForSegue?
【发布时间】:2013-02-08 21:20:18
【问题描述】:

如何使用 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”

【问题讨论】:

  • 你在 [[segue destinationViewController] setDetailItem:object]; 线上遇到错误了吗?
  • 显然theNews实际上是一个字典,而不是一个数组。你在哪里创建的?

标签: iphone ios xcode uitableview


【解决方案1】:

您的theNews 数组中的数据似乎有点像NSDictionary。没有称为- objectAtIndexPath:NSDictionary 的方法。您应该改用– objectForKey:(或其他一些方法)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-12-20
    • 1970-01-01
    • 2014-10-07
    • 2020-07-18
    • 2011-06-14
    • 1970-01-01
    • 2014-02-13
    • 1970-01-01
    相关资源
    最近更新 更多