Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How pass data in seque ios5 storyboard uitableview to detail view

I'm creating an app in ios5 using storyboards. I have a tableviewcontroller embedded in a navigation controller and when you click on the cells in the tableviewcontroller some detail about that cell topic should be passed to a detail view. I use a plist to populate the tableview and the detail view. I've done this fine without using storyboard but want to learn how to use storyboard. I have seque going to my detail view from the tableviewcontroller.

My code for the seque is:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([segue.identifier isEqualToString:@"DetailViewControllerSeque"])
    {   DetailViewController *detailViewController = [segue destinationViewController];  
        NSString *path = [[NSBundle mainBundle] bundlePath];
        NSString *finalPath = [path stringByAppendingPathComponent:@"questList.plist"];
        NSArray *tempArray = [finalPath valueForKey:@"description"];
        NSString *descriptionString = [tempArray valueForKey:@"description"];
        detailViewController.detailDescriptionText.text = descriptionString;    
    }
}

Thanks for any help.

like image 648
Catacomber Avatar asked Sep 10 '25 06:09

Catacomber


2 Answers

I was having the same problem (from lack of experience with iOS5).

It turns out that is an example app with the iOS5 SDK which has a table view that uses segues when a table cell is tapped : "Simple Drill Down".

https://web.archive.org/web/20130513140140/http://developer.apple.com:80/library/ios/#samplecode/SimpleDrillDown/Introduction/Intro.html

You do set the segue at the table cell and give it a name in the storyboard file.

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

    /*
     When a row is selected, the segue creates the detail view controller as the destination.
     Set the detail view controller's detail item to the item associated with the selected row.
     */
    if ([[segue identifier] isEqualToString:@"ShowSelectedPlay"]) {

        NSIndexPath *selectedRowIndex = [self.tableView indexPathForSelectedRow];
        DetailViewController *detailViewController = [segue destinationViewController];
        detailViewController.play = [dataController objectInListAtIndex:selectedRowIndex.row];
    }
}
like image 115
M. Bedi Avatar answered Sep 12 '25 20:09

M. Bedi


I got the same problem, Followed parts of Ray Wenderlich tutorial and found that you need to select table cell and Ctrl-Drag to your viewcontroller. Then call performSegueWithIdentifier in didSelectRowAtINdexPath.

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
     [self performSegueWithIdentifier:@"mySegueId" sender:self];
}

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{   
        NSLog(@"prepareForSegue: %@", segue.identifier  );      
        if ([segue.identifier isEqualToString:@"mySegueId"])
        {
            DetailController *detailController = segue.destinationViewController;
            detailController.delegate = (id)self;
            detailController.selected = selectedRow;
        }   
}
like image 36
neefje Avatar answered Sep 12 '25 20:09

neefje