简体   繁体   English

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

[英]Table View View Controller Show Next View

Im working with table view controllers within story board. 我在故事板中使用表视图控制器。

I currently have one tableview controller embedded in navigation controller in my storyboard. 我目前在故事板中有一个嵌入导航控制器的tableview控制器。 This table view controller is linked to an ObjectiveC file. 此表视图控制器链接到ObjectiveC文件。

Through code i can display another table view controller with the correct data using the tableView didSelectRowAtIndexPath method. 通过代码,我可以使用tableView didSelectRowAtIndexPath方法显示另一个具有正确数据的表视图控制器。

code: 码:

- (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];

}

But if i try to add another table view controller in storyboard, associate it with an objectiveC view controller file and connect the first TVC to it, That table view controller is not shown upon running the code. 但是,如果我尝试在storyboard中添加另一个表视图控制器,将其与objectiveC视图控制器文件关联,并将第一个TVC连接到它,在运行代码时不显示该表视图控制器。

I need to customise the second table view visually and have tried to use a segue push...as follows: 我需要直观地自定义第二个表视图并尝试使用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];


    }
}

But when i run this code, the second table view controller doesn't even load although the application doesn't crash. 但是,当我运行此代码时,第二个表视图控制器甚至不加载,尽管应用程序不会崩溃。

Whatever I am doing wrong must be simple, any help would be appreciated. 无论我做错什么都必须简单,任何帮助都会受到赞赏。

Thank You 谢谢

Simple You have to navigate through below code. 简单您必须浏览下面的代码。 (No need to set storyboard when you working in same storyboard ViewController) (在同一个故事板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  
    }  
}  

Do NOT Alloc init your new view controller. 不要 ALLOC初始化新视图控制器。 Use this code instead: 请改用此代码:

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

For MainStoryboard write your storyboard name and for coolID write your view controller id name which you set in your storyboard. 对于MainStoryboard编写故事板名称,并为coolID编写您在故事板中设置的视图控制器ID名称。

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

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