ios - 将属性传递给另一个 View

标签 ios objective-c storyboard segue uistoryboardsegue

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

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 连接的任何内容时它会崩溃。为什么会发生这种情况?我该如何解决这个问题?

最佳答案

您正在使用发件人来获取您的 selectedCell。

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

[self PerformSegueWithIdentifier:@"projectDetailsS​​egue"发件人:self];

你应该做的是:

[self PerformSegueWithIdentifier:@"projectDetailsS​​egue"发件人:*yourCell*];

关于ios - 将属性传递给另一个 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18206503/

相关文章:

ios - 行为类似于 NSUserDefaults 的 iCloud 键值存储

ios - 带有部分和搜索字段的 UITableView

ios - 如何在其他 UIViewController 中设置 UIViewController 的位置和大小

ios - 为什么我的代码只能在 DispatchQueue.main.async block 内运行?

ios - 一个 Storyboard中 iPhone 和 iPad 的不同方向

iphone - 点击iPhone通知中心的消息时如何转到特定 View ?

objective-c - 只需点击一下即可在 Twitter 上发帖 - 就像 Instagram 一样

iphone - 在 iOS 上使用 MKNetworkKit 进行流式传输

ios - 如何检查 UISegmentedControl 特定段是否已启用?

ios - 如何以编程方式导航到另一个 View Controller ,在 ios 9 中使用 "over current context "表示, Objective-C