Search code examples
iphoneobjective-cios5storyboard

ViewController does not change using Storyboard


In my storyboard, I have Root ViewController which is table ViewController and another is ViewController. Now with the prototype cell, I have connected the ViewController with push segue. Now I want some navigation in ViewController i.e adding button image view etc. But the changes do not apply to ViewController. What is the problem? Even I have disconnected the segue from cell, but still when I click on the cell the view is showed.

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
//Detail *d = [[Detail alloc] init];
if ([[segue identifier] isEqualToString:@"detail"]) {
    NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
    d = [segue destinationViewController];
    d.idd = [array2 objectAtIndex:indexPath.row];

    //detailViewController.treeData = [self.ds objectAtIndex:[self.tableView indexPathForSelectedRow].row];

}

}


Solution

  • First, make sure it's connected and the name of the segue matches the one in your code. Second, it has to be:

    -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
    if ([[segue identifier] isEqualToString:@"detail"]) {
        detailViewController *dcv = [[detailViewController alloc] init];
        dvc = [segue destinationViewController];
        dvc.treeData = [self.ds objectAtIndex:[self.tableView indexPathForSelectedRow].row];
    }  
    

    You have to create an instance of the ViewController you wanna navigate to and assign it to [segue destinationViewController] and then initialize it as you want (fill TextFields and so). I didn't understand what do you mean by Detail variable but hope that helps :)