私は本当に明白な何かを見逃しているかもしれませんが、プロジェクトをストーリーボードに移行しようとしていますが、テーブルビューコントローラーにユーザーが定義したデータを表示させるのに苦労しています。
基本的に、プロジェクトはメディアピッカーを使用して曲のキューを作成し、アプリが完全に再生されます。このユーザー定義リストをテーブルビューで表示しようとすると、問題が発生します。情報がまったく表示されません。(私の古い.xibファイルは問題なく動作しました!)。
テーブルビューコントローラの私の.h:
#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
と私の.m:
#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
なぜそれが何も返さないのかについて完全なミスをしています!