iPhone在UITableViewCell中包装文本

iPhone在UITableViewCell中包装文本,iphone,objective-c,xcode,uitableview,word-wrap,Iphone,Objective C,Xcode,Uitableview,Word Wrap,我正在尝试创建一个UITableView单元格,上面用大字体写着“在线查看此奉献”。我遇到的问题是单元格中的文本没有包装,因此我最终得到了部分短语 我的代码是: // Customize the appearance of table view cells. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { // Get cell s

我正在尝试创建一个UITableView单元格,上面用大字体写着“在线查看此奉献”。我遇到的问题是单元格中的文本没有包装,因此我最终得到了部分短语

我的代码是:

// 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.textlab.numberOfLines=0;//多行


有人能告诉我如何包装我的文本吗?

除了将
numberOfLines
设置为零之外,还要设置换行模式:

cell.textLabel.lineBreakMode = UILineBreakModeWordWrap;

(未编译,但你明白了)。

除了将
numberOfLines
设置为零之外,还可以设置换行模式:

cell.textLabel.lineBreakMode = UILineBreakModeWordWrap;

(未编译,但你明白了)。

从iOS6开始,UILineBreakModeWordWrap已被弃用。你需要-

cell.textLabel.lineBreakMode = NSLineBreakByWordWrapping;

从iOS6开始,UILineBreakModeWordWrap已被弃用。你需要-

cell.textLabel.lineBreakMode = NSLineBreakByWordWrapping;

实际上,现在您必须使用
tableView:heightforrowatinexpath:
为该单元格提供自定义高度。但是,实际上,在实现此方法时,您需要为每一行提供一个高度,并为此特殊行提供一个特殊高度。不过,您不需要计算每一行的高度。如果要使用默认高度,只需返回
tableview.rowHeight
.cell.textlab.numberOfLines=2索引,因此现在必须使用
tableview:heightforrowatinexpath:
为该单元格提供自定义高度。但是,实际上,在实现此方法时,您需要为每一行提供一个高度,并为此特殊行提供一个特殊高度。不过,您不需要计算每一行的高度。如果要使用默认高度,只需返回
tableview.rowHeight
.cell.textlab.numberOfLines=2即可