2013-07-21 64 views
0

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

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 
+0

通过实现didSelectRowAtIndexPath和prepareForSegue并不清楚你想要做什么。在您创建或引用playlistItemViewController的每个方法中。如果您已经在故事板中制作了控制器并且正在使用segse,那么您无需实施didSelectRowAtIndexPath。 – rdelmar

+0

如果删除了didselectrow方法,因为我的确在使用准备for segue ...但我仍然获得0个播放器项目 –

+0

您在哪里获得0个播放列表项目?如果您将PrepareForSegue中的SelectedPlaylist记录下来,您会得到什么? – rdelmar

回答

0

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

你的播放列表视图控制器需要使用SPAsyncLoading加载播放列表,列表中的东西是:

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

播放列表加载可能需要一段时间,所以一定要确保你把一些“加载” UI。您还需要以类似的方式加载可见的曲目,然后才能使用它们的名称。

+0

我已经设法解决它。为segue方法做准备确实有些问题。所以我改变了这一点,并且比我在播放列表视图中添加了上面的代码并猜测了什么... IT WORKED ...感谢球员....所以再次非常感谢你的帮助.... –

相关问题