1

私は本当に明白な何かを見逃しているかもしれませんが、プロジェクトをストーリーボードに移行しようとしていますが、テーブルビューコントローラーにユーザーが定義したデータを表示させるのに苦労しています。

基本的に、プロジェクトはメディアピッカーを使用して曲のキューを作成し、アプリが完全に再生されます。このユーザー定義リストをテーブルビューで表示しようとすると、問題が発生します。情報がまったく表示されません。(私の古い.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

なぜそれが何も返さないのかについて完全なミスをしています!

4

2 に答える 2

0

私は最終的にこれを解決しました!- アプリを Storyboard ベースに転送した結果、Prepare for Segue を使用してデータをテーブルにプッシュする必要がありました。

于 2012-10-30T18:21:13.253 に答える
0

ストーリーボードで、テーブルのコンテンツが静的セルに設定されているかどうかを確認し、設定されている場合は動的プロトタイプに変更します。

また、コードの cellForRowAtIndexPath で、onobject 'cell' を宣言した場所です。直接比較if(cell == nil)すると、どこにも宣言されていません。

于 2012-10-11T02:44:03.073 に答える