1

テーブルセルの特定のケースでは、画像がセルに追加されます。セルが正しく表示されません。これが私が意味することの写真です:

ここに画像の説明を入力

2番目のロックアイコンはそこに属していません...どのように、またはなぜそこにたどり着くのかわかりません。この例では、配列のカウントが 2 であるため、追加のロックはセル内にさえありません。

これは、最初のロードでは発生しませんが、セルが最初にリロードされるとすぐに発生します。初期ロード機能はリロード機能と同じであるため、これも混乱を招きます。

セル自体のコードは次のとおりです。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [UITableViewCell configureFlatCellWithColor:[UIColor greenSeaColor] selectedColor:[UIColor wetAsphaltColor] reuseIdentifier:CellIdentifier inTableView:(UITableView *)tableView];

    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
        [cell configureFlatCellWithColor:[UIColor greenSeaColor] selectedColor:[UIColor wetAsphaltColor]];

    }

    Room *room;

    //is data filtered?
    if(isFiltered)
    room = [filteredTableData objectAtIndex:indexPath.row];
    else
    room = [roomList objectAtIndex:indexPath.row];


    cell.textLabel.text = room.roomName;
    cell.detailTextLabel.text = room.hostUsername;

    //lock icon or not
  if(room.password != nil)
{
    UIImageView *pw = [[UIImageView alloc] initWithImage:img];
    pw.tag = [room.rid integerValue];
    [pw setImage:img];
    pw.frame = CGRectMake(cell.frame.size.width - cell.frame.size.height, cell.frame.origin.y,
                          cell.frame.size.height - 2, cell.frame.size.height - 2);
    [cell.contentView addSubview:pw];
}
else{ //remove the content view if not needed
    [[cell.contentView viewWithTag:[room.rid integerValue]] removeFromSuperview];
}


    return cell;
}

記録として、これは iOS7 では発生しません (NDA の下にあることは知っていますが、役立つ場合はその事実に言及したかっただけです)。

4

2 に答える 2

0

最終的に独自の UITableViewCell を作成し、画像を初期化し、ロックに次の 2 つの関数を使用しました。

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {

        img = [UIImage imageNamed:@"password.png"];                 
        pw = [[UIImageView alloc] initWithImage:img];
        [pw setImage:img];
        pw.frame = CGRectMake(self.frame.size.width - self.frame.size.height, self.frame.origin.y,
                              self.frame.size.height - 2, self.frame.size.height - 2);
        pw.tag = 1;

    }
    return self;
}
-(void)enableLock{
    [self.contentView addSubview:pw];
}

-(void)disableLock{
    [[self.contentView viewWithTag:1]removeFromSuperview];
}
于 2013-08-31T00:11:48.820 に答える