Iphone 如何制作';返回字符';对于一个xml标记中有几行的文本,我解析它然后将其放入UItableView?

Iphone 如何制作';返回字符';对于一个xml标记中有几行的文本,我解析它然后将其放入UItableView?,iphone,xml,uitableview,return,line,Iphone,Xml,Uitableview,Return,Line,我想在UItableViewCell中显示,文本如下 第1行 第2行 我从像line1 line2这样的xml标记获得它 我试过很多东西,比如: (也叫br), \n其中仅显示“line1\n line2”, ]]>仅显示“line1line2”。 感谢您的帮助您是否将文本设置为:cell.textlab.text=myText 如果您将其发送到UILabel,UILabel不能有换行符。 您可以尝试使用UITextView创建自定义单元格,并将文本发送到该单元格 自定义单元格的示例: tabl

我想在UItableViewCell中显示,文本如下

第1行 第2行

我从像line1 line2这样的xml标记获得它

我试过很多东西,比如:

(也叫br),
\n其中仅显示“line1\n line2”,
]]>仅显示“line1
line2”。


感谢您的帮助

您是否将文本设置为:
cell.textlab.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

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

Paul,谢谢您的回答。我同意您的示例,但我正在尝试从xml标记获取文本,即使我在xml中写入line1\n line2,显示的文本也只是“line1\n line2”。我必须尝试将其作为实际的换行符写入并使用textView。e、 g.第1行第2行/PaulOk非常感谢Paul,它确实有用。让我总结一下。您的代码是正确的,除了一些错误:在quickListViewCell.h中,您编写了“@interface appCountryCategoryViewCell”,但实际上它是“@interface quickListViewCell”。我替换了行“[[cell textFieldText]setText:@“line 1\n line 2”;”通过cell.textFieldText.text=[self-nameforindexath:indexPath]在我的xml文件中,我在两个单词第1行第2行之间做了一个真正的换行。在名为QuickListViewCell.xib的xib中,我添加了一个QuickListViewCell。我添加了一个UItextView,其中链接了quicklistviewcell。
#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