2014-05-21 86 views
0

我有一個UITableViewCell,它有一個UITextView。當表加載每個UITextView中的所有文本出現在一行中時。我使用白色文本顏色在IB中創建了UITextView。如何讓它以多行顯示,爲什麼文本顏色會切換爲黑色?UITextView不顯示在多行中

每個UITableViewCell的高度是正確的。在我刷新表格後通過多行顯示文本,但出於某種原因停止工作。

如果您需要其他信息,請告訴我。

下面是相關代碼:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath object:(PFObject *)object { 

BIDChatCell *cell = (BIDChatCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

if (cell == nil) { 
    cell = [[BIDChatCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier]; 
} 

// Configure the cell 

cell.backgroundColor = [UIColor clearColor]; 

cell.userLabel.text = [object objectForKey:@"username"]; 
NSString *time = [object objectForKey:@"time"]; 
NSString *date = [time substringToIndex:10]; 
cell.timeLabel.text = date; 

NSString *chatText = [object objectForKey:@"text"]; 
UIFont *font = [UIFont systemFontOfSize:14]; 
CGSize size = [chatText sizeWithFont:font constrainedToSize:CGSizeMake(200.0f, 1000.0f) lineBreakMode:UILineBreakModeCharacterWrap]; 
cell.textStringView.frame = CGRectMake(75, 15, size.width +20, size.height + 20); 
cell.textStringView.font = [UIFont fontWithName:@"Helvetica" size:14.0]; 
cell.textStringView.text = chatText; 
[cell.textStringView sizeToFit]; 
[cell.textStringView.textContainer setSize:cell.textStringView.frame.size]; 

CGRect frame = cell.textStringView.frame; 
frame.size.height = cell.textStringView.contentSize.height; 
cell.textStringView.frame = frame; 

[cell layoutSubviews]; 
return cell; 

}

這裏是一個形象:Screenshot

+0

請嘗試添加:細胞layoutSubviews]恢復單元前 –

+0

你有沒有實現的'的tableView:heightForRowAtIndexPath :'方法? – bobnoble

+0

您能否提供包含textview的表格的屏幕截圖,即以正確和正確的方式。所以這會讓你的問題清楚,並會提供答案。否則你應該嘗試進行身高鍛鍊。 – nikhil84

回答

0

嘗試設置TextView的高度,像這樣:

CGRect frame = cell.textStringView.frame; 
frame.size.height = cell.textStringView.contentSize.height; 
cell.textStringView.frame = frame; 
+0

我嘗試了你的建議,但它沒有改變任何東西 – josealvarado111

0

是否UITextView的有適當的autoresizingMask

它可能需要將其設置爲(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)允許TextView的增長(因爲它通常使用一個UIScrollView代替)