user2512523
user2512523

Reputation: 1359

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

Upvotes: 0

Views: 629

Answers (2)

Vivek Gajbe
Vivek Gajbe

Reputation: 411

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  
    }  
}  

Upvotes: 2

Abdullah Shafique
Abdullah Shafique

Reputation: 6918

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.

Upvotes: 0

Related Questions