1

我在 if 语句中不断收到预期标识符

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell1";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];

        //NSDate *object = _objects[indexPath.row];

    if(cell == nil)
    {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]];
        // expected identifier
    }
4

3 回答 3

9

这里:

cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]];
       ^                                                                                                  ^

你有一对额外的括号。最外面的一对是多余的。

于 2013-04-29T15:27:18.410 回答
-1

您正在使用标识符“Cell”出列一个单元格并创建一个标识符为“Cell1”的新单元格,这就是为什么您总是在 if 语句中结束。

改变

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
于 2013-04-29T15:29:28.113 回答
-1

我不知道你为什么会这样,但是当你使用 dequeueReusableCellWithIdentifier:forIndexPath 时,你根本不需要那个 if 子句。该出队方法保证创建一个单元格。

于 2013-04-29T15:27:30.097 回答