如何将此didSelectRowAtIndexPath转换为可用于我的故事板的内容?

时间:2013-06-07 16:38:53

标签: iphone ios

好的,我正在构建我之前构建的相同项目,但现在我想使用故事板。我不能使用initWithNibName,因为我当然只有1个故事板。

这是方法

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

    ViewController2 *ViewController22 = [[ViewController2 alloc] initWithNibName:@"ViewController2" bundle:nil]; // What to do instad of that nib thing?


    ViewController22.pickedRoww = indexPath.row;

    [[self navigationController] pushViewController:ViewController22 animated:YES];
}

2 个答案:

答案 0 :(得分:1)

使用故事板处理导航的建议方法是使用segues。 Here is a great tutorial showing you how to set this up

基本上,您可以在storyboard中从table viewcontroller到ViewController2创建一个segue。然后,在didSelectRowAtIndexPath中,您调用[self performSegueWithIdentifier:@"mySegueId"];

答案 1 :(得分:0)

最好的方法是使用Segue并设置你需要设置的值。特别是在推动而不是模态。虽然我需要在故事板中为我的一个视图弹出一个模态视图控制器但我没有一个笔尖或一个segue。还有一种方法可以做到这一点,我想我也会给你这些信息以防万一。在我的一个应用程序中,我有这个代码,它通过一个按钮从警报表中删除,基本上我想用最后一个lat和long来呈现一个模态视图控制器,所以我可以设置一个新的地理围栏区域。

我的代码如下所示:

-(void)createNewRegion
{
    UIStoryboard *mainboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];

    UINavigationController *newRegionNavController = [mainboard instantiateViewControllerWithIdentifier:@"newRegionNav"];

    AlertDetailViewController *detailView = [newRegionNavController.viewControllers objectAtIndex:0];

    //[detailView setupTableForNewRegion];

    [self presentViewController:newRegionNavController animated:YES completion:^(void){
        [detailView setupTableForNewRegion];
        detailView.longitude = self.lastLong;
        detailView.latitude = self.lastLat;
        detailView.mainController = self;
    }];
}

所以几乎与从nib实例化viewcontroller的旧方法完全相同,除了这次你只是从故事板中做到这一点。希望有所帮助。

相关问题