UINavigationController 2 つの ViewController と UITableView を使用してリストを表示する単純な iOS アプリケーションを作成しようとしています。問題は、テーブルが NSArray からのデータの表示を拒否することです。すべてのデリゲートは、写真に見られるように設定されています。
ViewController の xib ファイルを作成するとすべてが機能しますが、最初の図に示すように、Storyboard に ViewController をもう 1 つドラッグして、そのクラスを ItemListViewController にリンクできる場合は、もう 1 つの xib ファイルは必要ありません。
ItemListViewController.h
#輸入 @interface ItemListViewController : UIViewController{ NSMutableArray *tblDataSource; IBOutlet UITableView *tblSimpleTable; } @property (割り当て) NSMutableArray *tblDataSource; @property (保持) IBOutlet UITableView *tblSimpleTable; @終わり
ItemListViewController.m
#import "ItemListViewController.h" @interfaceItemListViewController () @終わり @implementation ItemListViewController @synthesize tblDataSource,tblSimpleTable; - (id)initWithNibName:(NSString *)nibNameOrNil バンドル:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; もし (自己) { // カスタム初期化 } 自分自身を返します。 } - (void)viewDidLoad { [super viewDidLoad]; // ビューを読み込んだ後、追加の設定を行います。 UIColor *background = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"bg.png"]]; self.tblSimpleTable.backgroundColor = 背景; [バックグラウンドリリース]; NSArray * data = [NSArray arrayWithObjects:@"エッグ ベネディクト"、@"マッシュルーム リゾット"、@"フル ブレックファスト"、@"ハンバーガー"、@"ハムとエッグ サンドイッチ"、@"クリーム ブリュレ"、@"ホワイト チョコレート ドーナツ"、@"スターバックス コーヒー"、@"野菜カレー"、@"卵入り即席麺"、@"BBQ 豚肉入り麺"、@"豚肉入り和風麺"、@"緑茶"、@"タイ風シュリンプ ケーキ" , @"Angry Birds Cake", @"ハムとチーズのパニーニ", nil]; [tblDataSource setArray:データ]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // 再作成できるすべてのリソースを破棄します。 } #pragma mark - テーブル ビュー データ ソース - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { // セクション数を返します。 0 を返します。 } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { // セクション内の行数を返します。 NSLog(@"@%d",[tblDataSource カウント]); [tblDataSource カウント] を返します。 } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"セル"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (セル == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; } // セルを構成します... UIImage *placeholder = [UIImage imageNamed:@"icon.png"]; [cell.imageView setImage:placeholder]; cell.textLabel.text = [tblDataSource objectAtIndex:indexPath.row]; セルを返します。 } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { NSLog(@"行 @%d をクリック",indexPath.row); } @終わり
誰かが私を正しい方向に向けることができれば、私は何を間違っていますか.