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 句はまったく必要ありません。その dequeue メソッドは、セルを作成することが保証されています。

于 2013-04-29T15:27:30.097 に答える