0

I am trying to pass an array from one table ,and populate it in another table.The parent table is place upon a UINavigationController say "mainNavig".The child table is placed in another ViewController of name "SongsofAlbum".My didSelectRowAtIndexPath of parent table is as follows,

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{   
    albumName = [eliminateDupe objectAtIndex:indexPath.row];   
    temp = [dictforalbum allKeysForObject:albumName ];
    songs = [NSMutableArray arrayWithCapacity:[temp count]];
    for (NSString *filename in temp) {
        [songs addObject:[[filename lastPathComponent] stringByDeletingPathExtension]];
    }
      NSLog(@"songs are %@",songs);    
    songObj = [[SongsofAlbum alloc]initWithNibName:@"SongsofAlbum" bundle:nil];
    [mainNavig pushViewController:songObj animated:YES];
    songObj.albumname = albumName;
    songObj.songArray = songs;
    NSLog(@"the song object array is %@ ",songObj.songArray)    
}

The nslog of songObj.songArray returns the data in the above method .But the problem I face is ,when I call this songArray in the child view controller it returns NULL . I even property synthesized the arrays. Any suggestions?

Dhara
  • 4,093
  • 2
  • 36
  • 69

2 Answers2

0

But the problem I face is ,when I call this songArray in the child view controller it returns NULL . I even property synthesized the arrays.

In other ViewController you are creating a new instance of this class. The new instance will be NULL.

You do not need to create new instance infact you need to use this same object's value from there.

You can do this thing by: How to make button in child view to update information in its parent view?

Community
  • 1
  • 1
Anoop Vaidya
  • 46,283
  • 15
  • 111
  • 140
0

You can take your songs array in AppDelegate and then instead assigning songObj.songArray = songs you can assign it in your SongsofAlbum class's viewDidLoad like

AppDelegate *app;


- (void)viewDidLoad
{

    [super viewDidLoad];

    app=(AppDelegate *)[[UIApplication sharedApplication]delegate];

    songarray= [[NSMutableArray alloc]initWithArray:app.songs];
}

Hope this will work.

βhargavḯ
  • 9,786
  • 1
  • 37
  • 59
Shah Paneri
  • 729
  • 7
  • 28