简体   繁体   中英

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. This table view controller is linked to an ObjectiveC file.

Through code i can display another table view controller with the correct data using the tableView didSelectRowAtIndexPath method.

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.

I need to customise the second table view visually and have tried to use a segue push...as follows:

- (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)

(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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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