Iphone 情节提要表视图控制器未显示用户定义的音乐列表
我可能遗漏了一些非常明显的东西,但是: 我正在尝试将一个项目迁移到故事板中,但是我很难让我的表视图控制器显示用户定义的数据 基本上,该项目使用一个媒体选择器来创建一个歌曲队列,应用程序可以完美地播放这些歌曲。当我试图在表视图中显示这个用户定义的列表时,我的问题就开始了,它根本不显示任何信息!(我的旧.xib文件工作正常!) 表视图控制器的my.h:Iphone 情节提要表视图控制器未显示用户定义的音乐列表,iphone,xcode,uitableview,storyboard,Iphone,Xcode,Uitableview,Storyboard,我可能遗漏了一些非常明显的东西,但是: 我正在尝试将一个项目迁移到故事板中,但是我很难让我的表视图控制器显示用户定义的数据 基本上,该项目使用一个媒体选择器来创建一个歌曲队列,应用程序可以完美地播放这些歌曲。当我试图在表视图中显示这个用户定义的列表时,我的问题就开始了,它根本不显示任何信息!(我的旧.xib文件工作正常!) 表视图控制器的my.h: #import <UIKit/UIKit.h> #import <MediaPlayer/MediaPlayer.h> #i
#import <UIKit/UIKit.h>
#import <MediaPlayer/MediaPlayer.h>
#import "MusicViewController.h"
@protocol MusicTableViewControllerDelegate; // forward declaration
@interface MusicTableViewController : UITableViewController <MPMediaPickerControllerDelegate, UITableViewDelegate> {
__unsafe_unretained id <MusicTableViewControllerDelegate> delegate;
}
@property (nonatomic, assign) id <MusicTableViewControllerDelegate> delegate;
@property (nonatomic, strong) NSMutableArray *mediaItemCollectionTable;
@end
@protocol MusicTableViewControllerDelegate
// implemented in MainViewController.m
- (void) musicTableViewControllerDidFinish: (MusicTableViewController *) controller;
- (void) updatePlayerQueueWithMediaCollection: (MPMediaItemCollection *) mediaItemCollection;
@end
我完全不明白为什么它不归还任何东西 在情节提要中,检查表的内容是否设置为静态单元格。如果设置为静态单元格,请将其更改为动态原型
另外,在您的代码中,在cellforrowatinexpath中,您在哪里声明了onobject“cell”。我看到直接比较
如果(cell==nil)
它没有在任何地方声明。我最终解决了这个问题结果显示,我需要使用Prepare for Segue将数据推送到表中,这是将应用程序传输到基于情节提要的应用程序的结果。我将放置NSLog(@“Controller:%@,Queue:%@,Items:%@,Count:%d”,mainViewController,currentQueue,currentQueue.Items,[currentQueue.Items Count])代码>就在返回[currentQueue.items count]之前看看我得到了什么。我会试一试的!好主意!有趣的是,它返回“0”。至少我可以停止在这方面的努力。:)与控制器、队列或项目的零相反,为空?实际输出:控制器:(null)、队列:(null)、项目:(null)、计数:0在interface builder检查器的标识符字段中,单元格被声明为ok。
#import "MusicTableViewController.h"
#import "MusicViewController.h"
@interface MusicTableViewController ()
@end
@implementation MusicTableViewController
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
}
return self;
}
@synthesize delegate; // The main view controller is the delegate for this class.
@synthesize mediaItemCollectionTable; // The table shown in this class's view.
// Configures the table view>
- (void)viewDidLoad
{
[super viewDidLoad];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
MusicViewController *mainViewController = (MusicViewController *) self.delegate;
MPMediaItemCollection *currentQueue = mainViewController.userMediaItemCollection;
return [currentQueue.items count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (cell == nil) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault
reuseIdentifier: @"Cell"];
}
MusicViewController *mainViewController = (MusicViewController *) self.delegate;
MPMediaItemCollection *currentQueue = mainViewController.userMediaItemCollection;
MPMediaItem *anItem = (MPMediaItem *)[currentQueue.items objectAtIndex:indexPath.row];
cell.textLabel.text = [anItem valueForProperty:MPMediaItemPropertyTitle];
return cell;
}
#pragma mark - Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath: indexPath animated: YES];
@end