也許有人在外可以幫助我確定我的問題。我似乎不能使用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
通過實現didSelectRowAtIndexPath和prepareForSegue並不清楚你想要做什麼。在您創建或引用playlistItemViewController的每個方法中。如果您已經在故事板中製作了控制器並且正在使用segse,那麼您無需實施didSelectRowAtIndexPath。 – rdelmar
如果刪除了didselectrow方法,因爲我的確在使用準備for segue ...但我仍然獲得0個播放器項目 –
您在哪裏獲得0個播放列表項目?如果您將PrepareForSegue中的SelectedPlaylist記錄下來,您會得到什麼? – rdelmar