【问题标题】:prepareForSegue EXC_BAD_ACCESS at indexPath.rowprepareForSegue EXC_BAD_ACCESS 在 indexPath.row
【发布时间】:2017-05-16 07:25:44
【问题描述】:

我正在尝试通过 prepareForSegue 函数下的 segue 传递数据,但我不断收到 exc_bad_access。

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];

//NSIndexPath *indexPath = [NSIndexPath indexPathForRow:rowIndex inSection:0];
// Make sure your segue name in storyboard is the same as this line
if ([[segue identifier] isEqualToString:@"itemListSegue"])
{
    itemList *vc = [segue destinationViewController];
    vc.inv = [inv_list objectAtIndex:indexPath.row];
    vc.title = vc.inv;
}
}

下面是我遇到的错误

编辑: inv_list 声明如下:

@interface downloadInv (){
NSMutableArray *inv_list;
}

在 viewDidLoad 中:

inv_list = [[NSMutableArray alloc] init];

内容:

vc.inv 是 inv_list 中的一个特定元素,我想在选择表时将其传递给目标视图控制器。

声明如下:

@interface itemList : UITableViewController

@property(nonatomic, strong) NSString *inv;
@end

有人知道如何解决这个问题吗?

提前致谢。

【问题讨论】:

  • inv_list 是什么?它是数组吗?确保您在 prepareforsegue 中获得了正确的 indexpat 而不是 nil!
  • 请说明inv_list是如何定义的?
  • 向我们展示列表是什么,以及您要填充的 vc 的属性是什么。
  • 尝试将其声明为强属性
  • 根据代码,inv_list根本没有声明为属性,试试@property (strong, nonatomic) NSMutableArray * inv_list;

标签: ios objective-c iphone xcode xcode8


【解决方案1】:

因为in_list 未被声明为强属性,它可能正在被释放。 尝试像这样声明它:

@property (strong, nonatomic) NSMutableArray * inv_list;

【讨论】:

    【解决方案2】:

    能否请您检查您的 segue 标识符,如果没有给出,可能会导致异常

    否则,如果它是像这样的强属性:

    @property(nonatomic,strong) NSString *inv_list;
    

    或许能解决问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-25
      • 2012-12-19
      相关资源
      最近更新 更多