1

Can anyone tell me why my code isn't showing any results in my table view. Here is my code. I already tried to change the @"@" into indexPath.row without any luck. I 'm looking for any answer into the right direction. I'm fairly new to xcode and objective-c. I would really appreciate any help.

-(void)waitAndFillPlaylistPool {
    // arrPlaylist -> mutablearray which stores the value of loaded playlist in order to use it later


    [SPAsyncLoading waitUntilLoaded:[SPSession sharedSession] timeout:kSPAsyncLoadingDefaultTimeout then:^(NSArray *loadedession, NSArray *notLoadedSession)
     {
         // The session is logged in and loaded — now wait for the userPlaylists to load.
         NSLog(@"[%@ %@]: %@", NSStringFromClass([self class]), NSStringFromSelector(_cmd), @"Session loaded.");

         [SPAsyncLoading waitUntilLoaded:[SPSession sharedSession].userPlaylists timeout:kSPAsyncLoadingDefaultTimeout then:^(NSArray *loadedContainers, NSArray *notLoadedContainers)
          {
              // User playlists are loaded — wait for playlists to load their metadata.
              NSLog(@"[%@ %@]: %@", NSStringFromClass([self class]), NSStringFromSelector(_cmd), @"Container loaded.");

              NSMutableArray *playlists = [NSMutableArray array];
              [playlists addObject:[SPSession sharedSession].starredPlaylist];
              [playlists addObject:[SPSession sharedSession].inboxPlaylist];
              [playlists addObjectsFromArray:[SPSession sharedSession].userPlaylists.flattenedPlaylists];

              [SPAsyncLoading waitUntilLoaded:playlists timeout:kSPAsyncLoadingDefaultTimeout then:^(NSArray *loadedPlaylists, NSArray *notLoadedPlaylists)
               {
                   // All of our playlists have loaded their metadata — wait for all tracks to load their metadata.
                   NSLog(@"[%@ %@]: %@ of %@ playlists loaded.", NSStringFromClass([self class]), NSStringFromSelector(_cmd),
                         [NSNumber numberWithInteger:loadedPlaylists.count], [NSNumber numberWithInteger:loadedPlaylists.count + notLoadedPlaylists.count]);
                   NSLog(@"loadedPlaylists >> %@",loadedPlaylists);

                   arrPlaylist = [[NSMutableArray alloc] initWithArray:loadedPlaylists];
                   NSLog(@"arrPlaylist >> %@",arrPlaylist);

               }];
          }];
     }];
}


- (NSInteger) tableView:(UITableView *) tableView numberOfRowsInSection:(NSInteger)section {

    return [arrPlaylist count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }

        cell.textLabel.text = [arrPlaylist objectAtIndex:indexPath.row];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;


    return cell;
}
Danhi Bus
  • 19
  • 4
  • Are you sure your code running successfully, without Crashing on [arrPlaylist objectAtIndex:@"%@"]; this line? – Tirth Jul 07 '13 at 17:21
  • Where is the code of reloading UITableView after downloading all array data? Are you sure you properly set UITableViewDelegate and UITableViewDataSource? – Tirth Jul 07 '13 at 17:22
  • You are referring array's value incorrectly at the following line of code cell.textLabel.text = [arrPlaylist objectAtIndex:@"%@"] as you are not specifying which index the value should be taken from the array, it should be cell.textLabel.text = [arrPlaylist objectAtIndex:indexPath.row]. – ldindu Jul 07 '13 at 19:09
  • 1
    Agreed with @iAmbitious comment!!! – ldindu Jul 07 '13 at 19:17
  • i changed it without any luck...my table view is still not showing any data. – Danhi Bus Jul 07 '13 at 19:44
  • what do you exactly mean by reloading UITableView – Danhi Bus Jul 07 '13 at 19:45
  • @iAmbitious The funny thing is when i post a NSLog underneath my array count within rows. the output isn't showing any. it isn't showing any messag or even a number of playlist I used the following NSLog: // NSLog(@"%i", [arrPlaylist count]); – Danhi Bus Jul 07 '13 at 23:10

1 Answers1

0

It's hard to tell what you're doing in the method, waitAndFillPlaylistPool, but if this is taking any time to get this data, then you need to call reloadData on your table view ([self.tableView reloadData]) as the last line in that method (or when any async method returns -- I can't tell where that might be in your code).

rdelmar
  • 103,982
  • 12
  • 207
  • 218
  • GREAT...i did create an reloadData within the end of my method. I than created an propety outlet of my tableview naam and indeed it worked....there was an problem with retreiving the name but i managed to change the code by referring to the name NSString. thanks a lot all of you this was my first time using stackoverflow and your help was great. ALL OF YOU....Thanks...I'm still wondering why it is nescessary to use reloadData. – Danhi Bus Jul 08 '13 at 09:55
  • @DanhiBus, the table view calls its methods right after the view controller's viewDidLoad method runs (but before viewWillAppear), so if you have an asynchronous process that gets the data needed for the table, the table will have already called numberOfRows (which will be 0 if your array hasn't been populated yet). So, you need to to call reloadData after your asynchronous process which causes the table view to call its data source methods again. If my answer helped solve your problem, you should accept it by clicking on the arrow. – rdelmar Jul 08 '13 at 14:54