繁体   English   中英

表视图控制器显示下一个视图

[英]Table View View Controller Show Next View

我在故事板中使用表视图控制器。

我目前在故事板中有一个嵌入导航控制器的tableview控制器。 此表视图控制器链接到ObjectiveC文件。

通过代码,我可以使用tableView didSelectRowAtIndexPath方法显示另一个具有正确数据的表视图控制器。

码:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    WorkoutType *workoutType = (WorkoutType *)[self.fetchedResultsController objectAtIndexPath:indexPath];
    WorkoutSetViewController *detailViewController = [[WorkoutSetViewController alloc] initWithWorkoutType:workoutType];

    [self.navigationController pushViewController:detailViewController animated:YES];

}

但是,如果我尝试在storyboard中添加另一个表视图控制器,将其与objectiveC视图控制器文件关联,并将第一个TVC连接到它,在运行代码时不显示该表视图控制器。

我需要直观地自定义第二个表视图并尝试使用segue push ...如下所示:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([[segue identifier] isEqualToString:@"show"]) {



        NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];

        WorkoutType *workoutType = (WorkoutType *)[self.fetchedResultsController objectAtIndexPath:indexPath];
        //WorkoutSetViewController *detailViewController = [[WorkoutSetViewController alloc] initWithWorkoutType:workoutType];
        WorkoutSetViewController *destViewController = segue.destinationViewController;
        destViewController.workoutType = workoutType;
         //[self.navigationController pushViewController:detailViewController animated:YES];


    }
}

但是,当我运行此代码时,第二个表视图控制器甚至不加载,尽管应用程序不会崩溃。

无论我做错什么都必须简单,任何帮助都会受到赞赏。

谢谢

简单您必须浏览下面的代码。 (在同一个故事板ViewController中工作时无需设置故事板)

(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath  
{  
    if(indexpath.row==0)//for first row click  
    {  
         WorkoutSetViewController *objWorkoutSetVC=[[WorkoutSetViewController alloc] i  nitWithNibName:@"WorkoutSetViewController" bundle:nil];  
        [self.navigationController pushViewController:objWorkoutSetVC animated:YES];  
    }  
    else if(indexpath.row==1)//for second row click  
    {  
        //Put code in which screen you have to navigate  
    }  
}  

不要 ALLOC初始化新视图控制器。 请改用此代码:

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
WorkoutSetViewController *detailViewController = (WorkoutSetViewController *)[storyboard instantiateViewControllerWithIdentifier:@"coolID"];
[self.navigationController pushViewController:detailViewController animated:YES];

对于MainStoryboard编写故事板名称,并为coolID编写您在故事板中设置的视图控制器ID名称。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM