【问题标题】:Passing property to another view将属性传递给另一个视图
【发布时间】:2013-08-14 21:59:33
【问题描述】:

prepareForSegue 方法有问题。我需要将NSString 从一个视图传递到另一个视图,但我得到的只是:

2013-08-13 12:13:45.765 DailyPhotos[12551:907] -[ArchiveViewController textLabel]: unrecognized selector sent to instance 0x1e5592f0
2013-08-13 12:13:45.775 DailyPhotos[12551:907] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[ArchiveViewController textLabel]: unrecognized selector sent to instance 0x1e5592f0'
*** First throw call stack:
(0x328852a3 0x3a52a97f 0x32888e07 0x32887531 0x327def68 0x813dd 0x34a1ade9 0x8174d 0x3474f28d 0x347d1f81 0x33193277 0x3285a5df 0x3285a291 0x32858f01 0x327cbebd 0x327cbd49 0x3638f2eb 0x346e1301 0x78fb9 0x3a961b20)
libc++abi.dylib: terminate called throwing an exception

这是我的prepareForSegue 实现:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Checking the segue to perform
    if ([[segue identifier] isEqualToString:@"projectDetailsSegue"]) {
        AlbumViewController *destinationView = [segue destinationViewController];
        // Creating variable with selected cell
        UITableViewCell *selectedCell = (UITableViewCell *)sender;
        //  Passing the cell title to destination cell
        destinationView.projectTitle = @"tmp";
        NSLog(@"%@", selectedCell.textLabel.text);
    }
}

现在我正在传递 @"tmp" 并且它可以工作,但是当我尝试传递与 selectedCell 相关的任何内容时,它会崩溃。为什么会这样?我该如何解决这个问题?

【问题讨论】:

  • 我猜这是因为idUITableViewCell 之间的这种转换。告诉我你想看哪一部分,因为我认为问题出在我上面发布的这个示例中。

标签: ios objective-c storyboard segue uistoryboardsegue


【解决方案1】:

您正在使用 sender 获取您的 selectedCell。

但正如您在错误中看到的,您的发送者不是 UITableViewCell,而是 ArchiveViewController。可能是因为你正在做一个:

[self performSegueWithIdentifier:@"projectDetailsSegue" sender:self];

你应该做的是:

[self performSegueWithIdentifier:@"projectDetailsSegue" sender:*yourCell*];

【讨论】:

  • 但是我怎样才能得到我需要的单元格并通过它呢?或者我怎样才能获得选定的单元格?
  • -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath可以拨打[tableView cellForRowAtIndexPath:indexPath];
猜你喜欢
  • 2022-06-10
  • 2014-02-21
  • 1970-01-01
  • 1970-01-01
  • 2014-04-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-03-01
相关资源
最近更新 更多