通过自定义UITableViewCell推送到新的UIViewController

时间:2012-06-28 20:54:33

标签: iphone ios5 storyboard

我正在使用此功能,但它不起作用。我正在使用StoryBoard和xcode 4.3。

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Navigation logic may go here. Create and push another view controller.
    [tableView deselectRowAtIndexPath:indexPath animated:YES];

     pushnavViewController *detailViewController = [[pushnavViewController alloc] initWithNibName:@"pushnavViewController" bundle:nil];

    detailViewController.pushh.text = [listt objectAtIndex:indexPath.row];
     // Pass the selected object to the new view controller.
     [self.navigationController pushViewController:detailViewController animated:YES];

}

3 个答案:

答案 0 :(得分:1)

这是答案:

当您使用故事板时,您必须使用

pushnavViewController *detailViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"pushnavViewController"];

不是

     pushnavViewController *detailViewController = [[pushnavViewController alloc] initWithNibName:@"pushnavViewController" bundle:nil];

另外,不要忘记从st​​oryborad设置标识符。

答案 1 :(得分:0)

我以为我会从评论中拿出这个,然后尝试解决方案。对不起,这不是一个直接的解决方案,而是更多的建议......

也许最好的办法是(如果您使用Xcode 4.x)创建一个新项目,选择“Master-Detail Application”模板。查看AppDelegate类,看看如何将MasterViewController添加为UINavigationController的根视图控制器。了解其工作原理并尝试将其应用于您的情况。

另外,请查看UINavigationController的类引用。

答案 2 :(得分:0)

1-创建故事板标识符:pushnavViewController    单击ViewController,选择选项卡标识检查器==>故事板ID:pushnavViewController

2-使用Storyboard标识符启动UIViewController

 UIStoryboard *mainStoryboard = self.storyboard;
    UIViewController *mainViewController = [mainStoryboard instantiateViewControllerWithIdentifier:@"pushnavViewController"];

3-推送到另一个ViewController  [self.navigationController pushViewController:mainViewController animated:YES];

以下是代码:

-(void) openABCPage
{
    UIStoryboard *mainStoryboard = self.storyboard;
    UIViewController *mainViewController = [mainStoryboard instantiateViewControllerWithIdentifier:@"pushnavViewController"];
    [self.navigationController pushViewController:mainViewController animated:YES];

}