0

我想在 UItableViewCell 中显示,文本如

线 1 线 2

我从像 line1 line2 这样的 xml 标签中得到它

我尝试了很多东西,比如: <br/> (also &lt;br&gt;),
\n which only displays "line1 \n line2",
<![CDATA[<br >]]> which only displays "line1 <br> line2".

谢谢您的帮助

4

1 回答 1

1

您是否将文本设置为:cell.textLabel.text = myText

在这种情况下,您将其发送到 UILabel,而 UILabel 不能有换行符。您可以尝试使用 UITextView 创建一个自定义单元格并将您的文本发送到那里。

自定义单元格示例:tableview 类:

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

    if (cell == nil){
        NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"quickListViewCell" owner:nil options:nil];

        for(id currentObject in topLevelObjects)
        {
            if([currentObject isKindOfClass:[quickListViewCell class]])
            {
                cell = (quickListViewCell *)currentObject;
                break;
            }
        }
    }

    [[cell textFieldText] setText:@"Line 1 \n Line 2"];

    return cell;
}

quickListViewCell.h

#import <UIKit/UIKit.h>

@interface appCountryCategoryViewCell : UITableViewCell {
    IBOutlet UITextView *textFieldText;
}

@property (nonatomic, retain) IBOutlet UITextView *textFieldText;

@end

quickListViewCell.m

#import "quickListViewCell.h"

@implementation quickListViewCell

@synthesize textFieldText;

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        // Initialization code
    }
    return self;
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {

    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}


- (void)dealloc {
    [super dealloc];
}


@end

在 IB 中创建一个 UITableViewCell 并将标识符设置为“quickListViewCell”。

于 2009-12-10T12:28:08.373 回答