Попытка вызова второго табличного представления с элементами выбранного списка воспроизведения в первом представлении

Может быть, есть кто-то, кто может помочь мне решить мою проблему. Я не могу отобразить элементы списка воспроизведения с помощью cocoalibspotify. Я настроил свой просмотр списка воспроизведения, и первый управляющий контроллер viewview показывает список воспроизведения, но когда я пытаюсь вызвать элементы выбранного списка воспроизведения, я получаю 0 номеров строк, как показывают мои выходные данные. первое представление показывает, как я передаю indexpath во второй viewcontroller. второй скрипт показывает мои.h и.m файлы контроллера представления playlistitemsTavle.

Overview.m - просмотр таблицы с плейлистами

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [playlistView deselectRowAtIndexPath:indexPath animated:NO];
    playlistItemViewController *trailsController = [[playlistItemViewController alloc] initWithStyle:UITableViewStylePlain];
    trailsController.currentPlaylist = [playlistArray objectAtIndex:indexPath.row];
    //[[self navigationController] pushViewController:trailsController animated:YES];
    [self getSongs];
}

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    if ([segue.identifier isEqualToString:@"showPlaylistItem"]) {
        UITableViewCell *BasicCell = (UITableViewCell *) sender;
        NSIndexPath *ip = [self.tableView indexPathForCell:BasicCell];
        SPPlaylist *selectedPlaylist = [playlistArray objectAtIndex:ip.row];

        playlistItemViewController *pivc = (playlistItemViewController *) segue.destinationViewController;
        pivc.currentPlaylist = selectedPlaylist;
    }
}

playlistitemsViewController.h -

   #import <UIKit/UIKit.h>
    #import "CocoaLibSpotify.h"
    #import "Simple_PlayerAppDelegate.h"
    #import "overViewController.h"


    @interface playlistItemViewController : UITableViewController

    {
        UITableView *tableView;
    }

    @property (retain, nonatomic) IBOutlet UITableView *tableView;

    @property (strong, readwrite, nonatomic) SPPlaylist *currentPlaylist;




    @end

playlistViewController.m - это должно вызывать элементы списка воспроизведения

#import "playlistItemViewController.h"


@interface playlistItemViewController ()

@end


@implementation playlistItemViewController {

}

@synthesize currentPlaylist;
@synthesize tableView;



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


- (void)viewDidLoad
{
    [super viewDidLoad];

}



- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    // Return the number of rows in the section.
    NSLog(@"numberOfRowsInSection: %d",[[currentPlaylist items] count]);
    return [[currentPlaylist items] count];
}

- (UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"SubtitleCell";
    UITableViewCell *cell = [aTableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

    cell.textLabel.text = [[[currentPlaylist items] objectAtIndex:indexPath.row] valueForKey:@"name"];

    return cell;


    if (indexPath.row == 0) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"SubtitleCell"];
        [[cell.backgroundView  superview] bringSubviewToFront:cell.backgroundView];
        cell.textLabel.text = @"";
    }
    else{
        if (cell == nil) {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"SubtitleCell"];
        }
        SPPlaylistItem * item = [[currentPlaylist items] objectAtIndex:[[currentPlaylist items]count] - indexPath.row];
        cell.textLabel.text = [item.item name];

        if (item.itemClass == [SPTrack class]) {
            SPTrack * track = item.item;
            cell.detailTextLabel.text = [track consolidatedArtists];
        }

    }
    return cell;


}


@end

1 ответ

Решение

Вам нужно дождаться загрузки плейлиста, прежде чем элементы станут доступны.

Ваш контроллер просмотра списка воспроизведения должен использовать SPAsyncLoading чтобы загрузить плейлист, перечислите это:

[SPAsyncLoading waitUntilLoaded:self.currentPlaylist timeout:kSPAsyncLoadingDefaultTimeout then:^(NSArray *loadedItems, NSArray *notloadedItems) {
    [self.tableView reloadData];
}];

Загрузка плейлиста может занять некоторое время, поэтому убедитесь, что вы установили некоторый пользовательский интерфейс "загрузки". Вам также нужно будет загрузить видимые треки аналогичным образом, прежде чем их имена станут доступны.

Другие вопросы по тегам