Ios 数据正在从UITableView中消失

Ios 数据正在从UITableView中消失,ios,objective-c,uitableview,Ios,Objective C,Uitableview,我正在构建一个iOS应用程序,顶部有一个自定义选项卡栏。当我单击主图标时,我希望它在选项卡栏的正下方显示一个tableview。目前我的代码就是这样做的,但是数据显示不正确。如果我将我的单元格限制为4个或更少(在NumberForowsInstruction中),数据将显示,如果我有15个单元格,数据会显示一秒钟,然后消失。我到处都在看教程,一切似乎都是正确的,数据将在独立视图中正确显示(就像我在story board中创建了一个类似于singleview的应用程序,并将其作为初始视图)。我不知

我正在构建一个iOS应用程序,顶部有一个自定义选项卡栏。当我单击主图标时,我希望它在选项卡栏的正下方显示一个tableview。目前我的代码就是这样做的,但是数据显示不正确。如果我将我的单元格限制为4个或更少(在NumberForowsInstruction中),数据将显示,如果我有15个单元格,数据会显示一秒钟,然后消失。我到处都在看教程,一切似乎都是正确的,数据将在独立视图中正确显示(就像我在story board中创建了一个类似于singleview的应用程序,并将其作为初始视图)。我不知道我错在哪里。下面是我在TableViewController类的实现文件中的代码:

- (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文件做任何更改


如果您需要我发布任何其他代码块/屏幕截图,请让我知道

单元格不应是ivar,而应是局部变量。您还需要在
tableView:cellforrowatinexpath:
方法中将单元格出列:

UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:@"CustomCell"];

您可能需要验证tableView的框架-例如,只需添加一个
NSLog(@“tableView框架%@”,NSStringFromCGRect(tableView.frame))在您的
cellForRowAtIndexPath
实现中。您说的“主图标”是什么意思?可能是主页按钮?当应用程序要传递到后台时,是否显示tableview?对吗?请添加
PrayerCell
代码和一个屏幕截图链接。我想你们不明白单元格是如何在表视图中回收的——乍一看,这相当复杂。一旦某个单元格从屏幕上滚下,iOS就会将其删除,您的
CellForRowatineXpath
需要准备在被要求时重新生成它。我注意到您在
CellForRowatineXpath
中缺少“cell”的声明。您是否遗漏了某些代码?我已将其添加到上述代码中。我忘了把它包括在我的帖子里。