2017-03-29 1 views
0

UITableviewにはチャットのような2つのUILabelsがあります。可視UITableviewが塗りつぶされ、余分なセルを追加すると、私のUILabelが消えてしまいます。テーブルを再読み込み/スクロールするとラベルが消えます

その他のUILabelsが表示されている可能性があります。それらの2つのチャットUILabelsだけが隠されています。誰も私に可能な解決策を提案することはできますか?

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath; 
{ 
ChatScreenViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ChatCell" forIndexPath:indexPath]; 
index = indexPath.row + 1; 
indexx = indexPath; 


cell.ChatLabel1.layer.cornerRadius = 8; 
cell.ChatLabel1.layer.masksToBounds = YES; 
cell.ChatLabel2.layer.cornerRadius = 8; 
cell.ChatLabel2.layer.masksToBounds = YES; 

cell.ImageviewLabel1.layer.cornerRadius = 20; 
cell.ImageviewLabel1.layer.masksToBounds = YES; 
cell.ImageviewLabel2.layer.cornerRadius = 20; 
cell.ImageviewLabel2.layer.masksToBounds = YES; 
cell.ImageviewLabel2.backgroundColor = [UIColor greenColor]; 



if([Replychat[indexPath.row] valueForKey:@"bot"] != NULL) 
{ 

    cell.ChatLabel1.text = [Replychat[indexPath.row] valueForKey:@"bot"]; 
    cell.ChatLabel2.hidden = YES; 
    cell.ImageviewLabel2.hidden = YES; 

    cell.TimeLabel1.text = TimeArray[indexPath.row]; 
} 
else 
{ 

    cell.ChatLabel2.text = [Replychat[indexPath.row] valueForKey:@"User"]; 
    cell.ChatLabel1.hidden = YES; 
    cell.ImageviewLabel1.hidden = YES; 
    cell.TimeLabel2.text = TimeArray[indexPath.row]; 
} 

return cell; 

}

+2

コード作業を追加します。スクリーンショットもあります。 –

+1

問題はセルの再利用性です。 –

+0

@meowsushあなたの質問をcellForRowAtIndexPathコードで更新する必要があります。大まかな推測では、配列を更新した後にあなたのUITableviewを再ロードしていない可能性があります。 –

答えて

1

Labels in custom TableView cells disappearing after scrolling

私のコードは、1つの分岐がYES = cell.ChatLabel2.hiddenを設定することができればelse文を持っています。他のブランチはcell.ChatLabel2.hidden = NO;を設定しません。だから、いったんラベルが隠されると、隠されてしまうことはありません。隠れたラベルのセルが再利用されると、ラベルは隠されたままになります。

セルを追加します.ChatLabel2.hidden = NO; (およびその他の 'inverse'設定が必要)をif文に追加します。

0

試してみてください。

//.... 
    cell.ImageviewLabel2.backgroundColor = [UIColor greenColor]; 
    // because tableview reuse uitableviewcell, so you must reset hidden status for lable 
    cell.ChatLabel2.hidden = NO; 
    cell.ChatLabel1.hidden = NO; 

    if([Replychat[indexPath.row] valueForKey:@"bot"] != NULL) 
    //.... 
0

この方法を試してみてください

  • (UITableViewCellの*)のtableView:(のUITableView *)のtableView cellForRowAtIndexPath:(NSIndexPath *)indexPath。 {

ChatScreenViewCell *細胞= [dequeueReusableCellWithIdentifierのtableView: "ChatCell" forIndexPath @:indexPath]。

(セル== NIL){

cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault 
           reuseIdentifier:@"ChatCell"]; 

}

インデックス= indexPath.row + 1の場合。

indexx = indexPath;

cell.ChatLabel1.layer.cornerRadius = 8;

cell.ChatLabel1.layer.masksToBounds = YES;

cell.ChatLabel2.layer.cornerRadius = 8;

cell.ChatLabel2.layer.masksToBounds = YES;

cell.ImageviewLabel1.layer.cornerRadius = 20;

cell.ImageviewLabel1.layer.masksToBounds = YES;

cell.ImageviewLabel2.layer.cornerRadius = 20;

cell.ImageviewLabel2.layer.masksToBounds = YES;

cell.ImageviewLabel2.backgroundColor = [UIColor greenColor];

if([Replychat [indexPath.row] valueForKey:@ "bot"]!= NULL) {

cell.ChatLabel1.hidden = NO;

cell.ChatLabel1.text = [Replychat [indexPath.row] valueForKey:@ "bot"];

cell.ChatLabel2.hidden = YES;

cell.ImageviewLabel2.hidden = YES;

cell.TimeLabel1.text = TimeArray [indexPath.row];他

}

{

cell.ChatLabel2.hidden = NO。

cell.ChatLabel2.text = [Replychat [indexPath.row] valueForKey:@ "User"];

cell.ChatLabel1.hidden = YES;

cell.ImageviewLabel1.hidden = YES;

cell.TimeLabel2.text = TimeArray [indexPath.row];

}

return cell;

}

関連する問題