0

上部にカスタム タブ バーがある iOS アプリを作成しています。ホームアイコンをクリックすると、タブバーのすぐ下にテーブルビューが表示されます。現在、私のコードはそれを行っていますが、データは正しく表示されません。セルを 4 以下 (numberFoRowsInSection 内) に制限すると、データが表示されます。たとえば、15 個のセルがある場合、データは一瞬表示されてから消えます。私は至る所でチュートリアルを見てきましたが、すべてが正しいようです。データはスタンドアロン ビューで正しく表示されます (ストーリー ボードでシングルビュー アプリケーションに似たものを作成し、それを初期ビューにしたように)。どこが間違っているのかわかりません。以下は、tableviewContoller クラスの実装ファイルのコードです。

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{

// Return the number of rows in the section.
return 4;//this works... but change to 15 it doesnt work
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath   *)indexPath
{
  PrayerCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CustomCell"];
if (cell == nil) {
    NSLog(@"cell is Nil"); //never hits this
    cell = [[PrayerCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"CustomCell"];
}

//the data showing is the correct data that i want to see
cell.dName.text = [[news objectAtIndex:indexPath.row] objectForKey:@"displayname"];
cell.priority.text = [[news objectAtIndex:indexPath.row]objectForKey:@"priority"];
cell.dateTime.text = [[news objectAtIndex:indexPath.row] objectForKey:@"datetime"];
cell.numPraying.text = @"2 praying";
cell.requestPreview.text = [[news objectAtIndex:indexPath.row] objectForKey:@"request"];

NSLog(@"created cell") //verify cell was made

return cell;
}

ここに私の PrayerCell.H ファイルがあります

@interface PrayerCell : UITableViewCell

@property (weak, nonatomic)IBOutlet UILabel *requestPreview;
@property (weak, nonatomic)IBOutlet UILabel *dName;
@property (weak, nonatomic)IBOutlet UILabel *dateTime;
@property (weak, nonatomic)IBOutlet UILabel *numPraying;
@property (weak, nonatomic)IBOutlet UILabel *priority;

@end

私は、prayerCell.M ファイルに変更を加えていません。

他のコードブロック/スクリーンショットを投稿する必要がある場合は、お知らせください。

4

1 に答える 1

0

セルは ivar ではなく、ローカル変数である必要があります。tableView:cellForRowAtIndexPath:メソッドでセルをデキューする必要もあります。

UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:@"CustomCell"];
于 2013-06-27T18:07:23.687 に答える