2011-05-27 40 views
0

我怎樣才能在UITableViewCell上有一個標籤,但在它的右側還有一個箭頭?披露三角沒有出現在我的UITableViewCell上

這是我的嘗試:

} else if(indexPath.row == 1) { 
     UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(50,0,200,21)]; 
     label.text = @"Select to change code"; 
     label.tag = 1; 
     label.textColor = [UIColor grayColor]; 
     cell.accessoryView = label; 
     cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 
    } 

但它不工作。我看到標籤,但沒有看到電池右側的箭頭。

+0

我想告訴你,你的問題的標題可能是不正確的...... – DreamOfMirrors 2011-05-27 11:56:40

+0

@DreamOfMirrors - 不再事實並非如此。 – Abizern 2011-05-27 11:57:33

回答

3

嘗試以下操作:

else if(indexPath.row == 1) { 
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(50,0,200,21)]; 
    label.text = @"Select to change code"; 
    label.tag = 1; 
    label.textColor = [UIColor grayColor]; 
    [cell addSubview:label];//i changed oonly this line 
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 
} 

希望它可以幫助你........

編輯:(因爲我不能評論的原因小的變化是在原始代碼你已經將標籤添加到單元格中,因爲它的accessoryType子視圖(有效地用你的標籤覆蓋它),而在修改後的代碼中,標籤被正確添加爲單元格的單獨子視圖

+0

這應該是[cell.contentView addSubview] - 不要直接添加東西到單元格。此外,如果使用默認標題和/或圖像視圖,它將簡單地重疊。 – 2011-05-27 12:42:51

0

你不能同時擁有自定義配件視圖和系統提供的視圖你得到cell.accessoryType。這個怎麼樣:

cell.textLabel.text = @"Select to change code"; 
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 
相關問題