Ios 为什么我的UITableViewCell指示空值

Ios 为什么我的UITableViewCell指示空值,ios,objective-c,uitableview,Ios,Objective C,Uitableview,我正在尝试使用UITableViewCell更改其标题和内容。但是,我在获取tableViewCell时遇到问题,因为当我调用以下方法时 UITableViewCell*cell=[tableView dequeueReusableCellWithIdentifier:CellIdentifier] 在该方法内部: -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *

我正在尝试使用UITableViewCell更改其标题和内容。但是,我在获取tableViewCell时遇到问题,因为当我调用以下方法时

UITableViewCell*cell=[tableView dequeueReusableCellWithIdentifier:CellIdentifier]

在该方法内部:

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ // 3
    static NSString *CellIdentifier = @"Flickr Photo Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; // Why is cell NULL?
    if(cell == nil){
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
设置断点后,我可以在调试器中看到该值为(null):


在我的故事板中,我将单元格标识符设置为
Flickr Photo cell

在尝试将单元格出列之前,您是否使用该标识符注册了nib或单元格类?注册通常在
viewDidLoad
中完成:

- (void)viewDidLoad {
    [super viewDidLoad];
    UINib *cellNib = [UINib nibWithNibName:@"NameOfFlickrPhotoCellNib" bundle:nil];
    [self.tableView registerNib:cellNib forCellReuseIdentifier:@"Flickr Photo Cell"];
}

您可以按代码创建单元格:

 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ // 3
static NSString *CellIdentifier = @"Flickr Photo Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
// Why is cell NULL?
if(!cell){
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
//here configure you cel..Be carefully this cell doen't anything of you storyboard cell.
NSLog(@"Cell is not nil:%@",[cell description]);
return cell;
}
或使用故事板(或xib)


是的,如果没有要出列的单元格,单元格可以是零。问题是单元格不是零。该单元格为空。我在代码后加入了一个检查nil,现在我将更新该检查以反映目标C中相同的内容
nil
nil
NULL
,以及
0
;只是每一个都被传统地用于不同的数据类型。@Austin但是为什么对nil的检查不起作用?@jacks4jokers或者也许我误解了。。。当单元格==NULL时,
if(cell==nil){
块是否正在执行?我使用的是故事板。我没有使用nib文件。我在IB中设置了我的单元格标识符。
 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"reuseINSTORYBOARD" forIndexPath:indexPath];

// Configure the cell...

return cell;
}