1

我正在使用来自 ray http://www.raywenderlich.com/913/sqlite-101-for-iphone-developers-making-our-app的以下教程

我让一切正常工作,除了从 didselectrow 填充的详细视图

这就是他所拥有的

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if (self.details == nil) {

        self.details = [[[FailedBanksDetailViewController alloc] initWithNibName:@"FailedBanksDetailViewController" bundle:nil] autorelease];        
    }
    FailedBankInfo *info = [_failedBankInfos objectAtIndex:indexPath.row];
    _details.uniqueId = info.uniqueId;
    [self.navigationController pushViewController:_details animated:YES];
    [self performSegueWithIdentifier:@"testID" sender:self.view];
}

但是它不适用于情节提要

谁能帮帮我,我到处找答案!!!

4

3 回答 3

1

目前您使用的代码是用于 bob 的 NIB 和情节提要。选择1并坚持下去。如果您使用故事板,只需执行 segue 然后处理prepareForSegue:sender:配置目标视图控制器。

于 2013-07-07T19:07:07.797 回答
0

尝试:

self.details = [self.storyboard instantiateViewControllerWithIdentifier:@"FailedBanksDetailViewController"];

主情节提要中的视图控制器在FailedBanksDetailViewController哪里。identifier

由于您使用的是http://www.raywenderlich.com,您可以在此处查看故事板示例。

于 2013-07-07T19:03:04.160 回答
0

几个选项:

  1. 您可以为要过渡到的场景提供“故事板 id”(您在 Interface Builder 中执行此操作),然后instantiateViewControllerWithIdentifier使用initWithNibName.

  2. 如果您在情节提要中使用单元原型,则根本不需要didSelectRowAtIndexPath方法,只需将单元原型中的转场添加到下一个场景即可。然后,您编写一个prepareForSegue将 传递uniqueId给下一个场景的方法。

    prepareForSegue可能看起来像:

    - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
    {
        if ([segue.identifier isEqualToString:@"DetailsSegue"])
        {
            NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
            FailedBankInfo *info = [_failedBankInfos objectAtIndex:indexPath.row];
            [(FailedBanksDetailViewController *)segue.destinationViewController setUniqueId:info.uniqueId];
        }
    }
    

    显然,替换DetailsSegue为您为 segue 的故事板 ID 提供的任何名称。

于 2013-07-07T19:05:49.467 回答