2014-10-20 87 views
0

我現在的followind可能有點過時的教程從iOS Apprentice關於地理定位。TextView裏面的表格單元格顯示不正確

無論如何,要完成的工作似乎極其簡單: 將text view置於table view cell之內。在故事板一切看起來馬麗娟,但是當我運行它,它看起來像下面呈現的畫面(TextView的覆蓋以下類別的表格單元格視圖項):

enter image description here

我有以下設置:

enter image description here

什麼是最好的方式來保持文本視圖內的表格視圖單元格和文本只是包裝,overllay-Y(所以它在CSS中調用 - 我是新手到iOS)將被添加到textview?

+1

使用行數爲0的UILabel,UITextView用於顯示和編輯文本。 – railwayparade 2014-10-20 20:42:52

+0

事實上,這將是用戶應該放置他的描述的地方,所以這必須是可編輯的。 – andi 2014-10-20 20:46:04

+2

使用自動佈局,並將文本視圖的頂部和底部固定到單元格的頂部和底部(使用任何所需的填充)。 – rdelmar 2014-10-20 20:52:15

回答

0

我@railwayparade你應該使用

cell.textLabel.numberOfLines = 0; 

使用heightForRowAtIndexPath計算單元需要的大小一致認爲是

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    // replace "THE_TEXT" with the text you are displaying and "TEXT_LABEL_FONT" with the font you're using in the cell 

    CGSize size = ["THE_TEXT" sizeWithFont:"TEXT_LABEL_FONT" constrainedToSize:CGSizeMake(self.table.bounds.size.width, HUGE_VALF) lineBreakMode:NSLineBreakByWordWrapping]; 
    return size.height; 
} 

你可能想繼承的UITableViewCell並重寫layoutSubviews設置爲textLabel到準確的大小,並添加填充,因爲你看到適合

-(void)layoutSubviews // in your UITableViewCell subclass 
{ 
    [super layoutSubviews]; 
    self.textLabel.frame = CGRectMake(0.0f,0.0f,self.contentView.bounds.size.width,self.contentView.bounds.size.height); 
} 

不要忘記,如果在佈局子視圖中添加寬度的填充,則必須更改heightForRowAtIndexPath中的約束寬度。