我遇到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
相关的任何内容时,它会崩溃。为什么会这样?我怎样才能重新解决这个问题?
答案 0 :(得分:1)
您正在使用发件人来获取您的selectedCell。
但正如您在错误中看到的那样,您的发件人不是UITableViewCell,而是ArchiveViewController。可能是因为你在做:
[self performSegueWithIdentifier:@"projectDetailsSegue" sender:self];
你应该做的是:
[self performSegueWithIdentifier:@"projectDetailsSegue" sender:*yourCell*]
;