2009-12-10 27 views

回答

1

你要爲喜歡的文字:cell.textLabel.text = myText

我這種情況下,你發送給UILabel,並且UILabels不能有換行符。 你可以嘗試的是用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」。

+0

Paul,謝謝你的回答。 我同意你的例子,但我試圖從XML標記中獲取文本,即使我在xml中寫入 line1 \ n line2,diplayed文本也只是「line1 \ n line2」。 – Eric 2009-12-11 11:11:22

+0

必須嘗試將其作爲實際換行符和使用textView進行編寫。 例如 線1 2號線 /保羅 – 2009-12-11 12:20:10

+0

好非常感謝保羅,它的工作。 所以我只是總結一下。 你的代碼是正確的,除了一些錯誤:在quickListViewCell.h中,你寫了'@interface appCountryCategoryViewCell',但它實際上是'@interface QuickListViewCell'。 我替換了'[[cell textFieldText] setText:@「Line 1 \ n Line 2」];''通過 cell.textFieldText.text = [自我nameForIndexPath:indexPath] 在我的XML文件,我做了兩個詞 1個線2號線之間真正的換行符。 在一個名爲QuickListViewCell.xib的xib中,我添加了一個QuickListViewCell。我添加了一個UItextView,其中我與quicklistviewcell鏈接。 – Eric 2009-12-11 16:01:59

相關問題