Question

I want to pass data from a TableViewController cell to a DetailViewContoller (UITableViewController) using a segue (ShowADVDetail) in Storyboard.

I've got a NSMutableArray 'stories' containing a parsed RSS feed.

I am using the following prepareForSegue, which passes the 'title' value of a cell:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
        { 
            if ([segue.identifier isEqualToString:@"ShowADVDetail"]) {

                NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow]; 
                int storyIndex = [indexPath indexAtPosition: [indexPath length] - 1];
                NSString *theTitle = [[stories objectAtIndex: storyIndex] objectForKey: @"title"];
                [[segue destinationViewController] setDetailItem:theTitle];


            }
    }  

With the following line I can pass the 'title' value of particular cell.

NSString *theTitle = [[stories objectAtIndex: storyIndex] objectForKey: @"title"];

I can also access the 'Description' value and 'link' value like so:

NSString *theDescription = [[stories objectAtIndex: storyIndex] objectForKey: @"description"];
NSString *theLink = [[stories objectAtIndex: storyIndex] objectForKey: @"link"];

But how can I pass all 3 values in my segue?

My didSelectRowAtIndexPath so far looks like this:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:NO]



        [self performSegueWithIdentifier:@"ShowADVDetail" sender:self];

}

Hope this make sense..

Thanks

Was it helpful?

Solution

I think I'm understanding your question right. You can achieve this by creating properties in your header file (of the detailviewcontroller) for the properties you want passed.

So your detailViewController header would look like:

@interface DetailListViewController : UIViewController
  @property (strong, nonatomic) NSString *storyName;
  @property (strong, nonatomic) NSString *storyDescription;
  ...
@end

Then in your storyboard, you can control-drag the segue from your tableview to a detailViewController.

In your tableviewcontroller import your detailViewController.h file and add code like:

-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
  NSIndexPath *indexPath = self.tableView.indexPathForSelectedRow;
  [segue.destinationViewController setStoryName:###however you get name###;
  [segue.destinationViewController setStoryDescription:###however you get desc###;
}

In this code, you can add your check of "If segue.identifier..."

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top