0

I'm actually a beginner on Objective C and I'm working on a App which display the schedule of a TV Channel through a Table View. Now I want to get more details when I click on one TV Show. So I use a segue and a viewController (it's a constraint of my program)

So now I want to pass my mutableArray ScheduleList and its index from my ScheduleListViewController to my TVDetailsViewController.

My code is like that, it may helps you to understand how my mutableArray scheduleList works. I tried something for the prepareForSegue part but I don't think it's the right way :

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    if ([segue.identifier isEqualToString:@"show"]) {
        NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
        TVDetailsViewController *destViewController = segue.destinationViewController;
        destViewController.details = [_scheduleList objectAtIndex:indexPath.row];
    }
}


- (id)initWithStyle:(UITableViewStyle)style
{
    self = [super initWithStyle:style];
    if (self) {
        // Custom initialization
    }
    return self;
}



- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"Your TV Show on RUV";

    // Download JSON
    NSData *JSONData = [NSData dataWithContentsOfURL:[NSURL URLWithString:JSON_FILE_URL]];
    // Parse JSON
    NSError* error;
    NSDictionary* json = [NSJSONSerialization
                          JSONObjectWithData:JSONData //1

                          options:kNilOptions
                          error:&error];
    NSArray* jsonResult = [json objectForKey:@"results"];
    _scheduleList = [[NSMutableArray alloc] init];

    for (id item in jsonResult) {
        TVShow *tvs = [[TVShow alloc] init];
        tvs.title = [item objectForKey:@"title"];
        tvs.startTime = [item objectForKey:@"startTime"];
        [_scheduleList addObject:tvs];
    }
}

Thanks for your help guys

LeBrequin
  • 137
  • 8
  • 2
    What is not working exactly? – Larme Mar 07 '16 at 16:24
  • I think I'm doing wrong to pass my data to the other view – LeBrequin Mar 07 '16 at 16:26
  • 1
    How are you catching the array that is sent though segue on the other end (on TVDetailsViewController)? – Teja Nandamuri Mar 07 '16 at 16:27
  • Is `[_scheduleList objectAtIndex:indexPath.row]` in `prepareForSegue:sender:` the correct `TVShow` object? What do you do in `TVDetailsViewController` to check/read that object? – Larme Mar 07 '16 at 16:28
  • how are you handling destViewController.details on the receiving end? can you log/po them? – valosip Mar 07 '16 at 16:28
  • This question has been answered already. [Link to Solution](http://stackoverflow.com/questions/7864371/how-to-pass-prepareforsegue-an-object) – Wakaan Mar 07 '16 at 16:29
  • and your `[self performSegueWithIdentifier:@"show" sender:self];`? – jose920405 Mar 07 '16 at 16:29
  • That's my question too (I forget to ask) but I don't how I can use my mutableArray details to have my details.title, details.startTime etc – LeBrequin Mar 07 '16 at 16:32
  • Your code looks fine to me, there must be an issue either in IB, in the receiving VC, in the Table View methods, or in the data you receive. Put breakpoints and check. For your second question, just do this in your receiving VC : `TVShow* tvs = self.details; id title = tvs.title; id startTime = tvs.startTime;` – Konrad Mar 07 '16 at 16:46
  • My NSObject TVshow* needs the index to work – LeBrequin Mar 07 '16 at 16:56

0 Answers0