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