我正在嘗試創建一個UITableView單元格,它用大字體顯示「在線查看這個靈脩」。我遇到的問題是單元格中的文本沒有包裝,所以我最終得到了一部分短語。iPhone在UITableViewCell中包裝文本
我對這個代碼是:
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
// Get cell
static NSString *CellIdentifier = @"CellA";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
// Display
cell.textLabel.textColor = [UIColor blackColor];
cell.textLabel.font = [UIFont systemFontOfSize:15];
if (item) {
// Item Info
NSString *itemTitle = item.title ? [item.title stringByConvertingHTMLToPlainText] : @"[No Title]";
// Display
switch (indexPath.section) {
case SectionHeader: {
// Header
switch (indexPath.row) {
case SectionHeaderTitle:
cell.textLabel.font = [UIFont boldSystemFontOfSize:15];
cell.textLabel.text = itemTitle;
break;
case SectionHeaderDate:
cell.textLabel.text = dateString ? dateString : @"[No Date]";
break;
case SectionHeaderURL:
cell.textLabel.text = @"View this devotional in full website";
cell.textLabel.textColor = [UIColor blackColor];
cell.textLabel.font = [UIFont systemFontOfSize:36];
cell.imageView.image = [UIImage imageNamed:@"Safari.png"];
cell.textLabel.numberOfLines = 0; // Multiline
break;
}
break;
}
case SectionDetail: {
// Summary
cell.textLabel.text = summaryString;
cell.textLabel.numberOfLines = 0; // Multiline
break;
}
}
}
return cell;
}
下面這行之前的工作,但它似乎沒有在這裏工作。
cell.textLabel.numberOfLines = 0; // Multiline
有人能告訴我如何來包裝我的文字?
它的工作原理,但現在的文本被切斷 –
事實上,現在你有使用'的tableView提供針對該小區的自定義高度:heightForRowAtIndexPath:'。但實際上,當您實現此方法時,您需要爲每一行提供一個高度,併爲此特殊行提供一個特殊高度。 –
雖然你不需要計算每一行的高度。如果你想使用默認高度,只需返回'tableview.rowHeight'。 – thomashw