2013-10-27 95 views
0

可能是一個簡單的問題,但我找不到答案。 當我設置我的textLabel時,它會覆蓋我在單元格的內容視圖中顯示的詳細信息披露按鈕,並通過故事板放入。現在它只顯示單元格被選中的時間。我的代碼如下所示:UITableViewCell textLabel覆蓋我的按鈕

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

User *user = [arr objectAtIndex:indexPath.row]; 

// Configure the cell... 
cell.textLabel.text = [user username]; 

return cell; 
} 

當我拿走cell.textLabel.text = [用戶名]時;它隨時顯示,如我所願。 任何提示?猜猜我得把一些代碼在我的按鈕...

+0

嘗試添加if(cell == nil){cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; }代碼在UITableViewCell *單元代碼下面。 –

+0

不,沒有成功。我認爲問題出在某種程度上的文本標籤中。我想這是一些限制問題,但不知道。 – Rhyder

回答

0

想通了......

要理解這個問題,你要明白,一個UITableViewCell只有三個空間 - ImageView的,爲textLabel和配件。當您設置textLabel時,它會覆蓋您在故事板的內容區域中創建的所有內容。我必須設置一個新的類,具有子類UITableViewCell並在其中設置自定義IBOutlets,然後將自定義類鏈接到我的TableView。

+0

它不覆蓋任何東西。 textLabel只佔用整個contentView。你的按鈕仍然在textLabel後面。 https://developer.apple.com/library/ios/documentation/userexperience/conceptual/TableView_iPhone/TableViewCells/TableViewCells.html#//apple_ref/doc/uid/TP40007451-CH7-SW10 –