0

也许外面有人可以帮助我解决我的问题。我似乎无法使用 cocoalibspotify 显示播放列表项。我已经设置了我的播放列表视图,第一个ableviewcontroller 显示了播放列表,但是当我尝试调用所选播放列表的项目时,我的输出显示似乎得到了 0 个行数。第一个视图显示了我如何将 indexpath 传递给 secondviewcontroller。第二个脚本显示了我的 playlistitemsTavle 视图控制器的 .h 和 .m 文件。

Overview.m - 带有播放列表的 tableView

- (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
4

1 回答 1

0

在项目可用之前,您需要等待播放列表加载。

您的播放列表视图控制器需要用于SPAsyncLoading加载播放列表,列出以下内容:

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

播放列表加载可能需要一段时间,因此请确保您设置了一些“正在加载”的 UI。您还需要以类似的方式加载可见轨道,然后才能使用它们的名称。

于 2013-07-22T12:07:26.330 回答