如何将信息从表视图传递到详细信息视图

时间:2016-07-16 06:39:29

标签: ios objective-c

首先,先谢谢! 其次,我用谷歌搜索并检查论坛的答案有帮助,但找不到任何帮助。我知道这是一个被问到很多的领域。

所以我试图从表视图中将信息推送到Detail视图控制器。信息在plist上。我用来获取此代码的教程很旧并使用了xib。使用故事板,它会抛出以下错误:

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle:

我知道这是因为我没有名为'DetailViewController'的xib文件。我希望这个(以及来自plist的信息)被推送到我的“DetailViewController”,这是在我的故事板中,但我找不到这样做所需的代码。

你可以帮我解决这个问题吗?我需要做出哪些改变?

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

NSString *BibleVerses = [BibleReading objectAtIndex:indexPath.row];
if (!self.detailViewController) {
    self.detailViewController = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil];
}
self.detailViewController.detailItem = BibleVerses;
[self.navigationController pushViewController:self.detailViewController animated:YES];
}

2 个答案:

答案 0 :(得分:0)

如果你的控制器在故事板中,你可以使用instantiateViewControllerWithIdentifier方法。

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

NSString *BibleVerses = [BibleReading objectAtIndex:indexPath.row];
if (!self.detailViewController) {
    self.detailViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"DetailViewController"];
}
self.detailViewController.detailItem = BibleVerses;
[self.navigationController pushViewController:self.detailViewController animated:YES];
}

答案 1 :(得分:0)

使用此代码,

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    NSString *BibleVerses = [BibleReading objectAtIndex:indexPath.row];
    UIStoryboard * storyBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    self.detailViewController = [storyboard instantiateViewControllerWithIdentifier:@"YourViewControllerIdentifierName"];

    self.detailViewController.detailItem = BibleVerses;
    [self.navigationController pushViewController:self.detailViewController animated:YES];
}

希望它有用

相关问题