I'm trying to access a property from view controller one, so I put the code in ViewDidLoad of SecondViewController:
SeriesViewController *teste = [[SeriesViewController alloc] init];
NSLog(@"%@", teste.seriesArray);
The array is null. The declaration of the property in VC1 is:
@property (strong, nonatomic) NSArray *seriesArray;
I'm calling second VC in method didSelectRowsAtIndexPath
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UIViewController *exercicios = [sb instantiateViewControllerWithIdentifier:@"ExerciciosViewController"];
[super tableView:tableView didSelectRowAtIndexPath:indexPath];
if ([[_seriesForDisplay objectAtIndex:indexPath.row] isEqualToString:@"Serie A"]) {
[exercicios setTitle:[_seriesForDisplay objectAtIndex:indexPath.row]];
NSLog(@"AGORA %@", array.exerciciosArray);
I also tried the opposite way, like this:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UIViewController *exercicios = [sb instantiateViewControllerWithIdentifier:@"ExerciciosViewController"];
[super tableView:tableView didSelectRowAtIndexPath:indexPath];
if ([[_seriesForDisplay objectAtIndex:indexPath.row] isEqualToString:@"Serie A"]) {
[exercicios setTitle:[_seriesForDisplay objectAtIndex:indexPath.row]];
ExerciciosViewController *array = [[ExerciciosViewController alloc] init];
array.exerciciosArray = _seriesArray;
NSLog(@"AGORA %@", array.exerciciosArray);
But the exerciciosArray, although is populated in this code at VC1, is empty when I get to VC2.
Thanks.
UPDATE
I was instantiating a new controller. Now, I'm just pointing to existing one. I'm getting a different error now at:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section, I have the lines:
NSLog(@"CONTADOR bla %li", _exerciciosArray.count); and:
return _exerciciosArray.count;
I get 4 items in the log just before crash with message:
-[__NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array'.