2011-10-10 113 views
2

我正在實施一個iphone應用程序。我已經使用自定義表格視圖單元實現了表格視圖。在每個表格單元中有7個標籤。我想把搜索欄放在表格視圖中。每當我嘗試搜索One標籤的值時,放置此標籤的行整體不會到達第一個位置,但標籤值會被第一個標籤的值替換。這意味着標籤的價值不會與整個行保持一致。如何解決這個問題,請給我一些解決方案。查看錶格視圖(自定義tableview單元格)

非常感謝。

回答

0

當前一段時間我遇到這個問題時,我碰到了一篇關於搜索欄的文章:http://www.raywenderlich.com/16873/how-to-add-search-into-a-table-view。這真的有幫助,但它不適用於自定義單元格。

因此,使用完全相同的方法中的鏈接,但在你的CustomCell.m類添加的這段代碼在你的initWithStyle:

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

     _label1 = [[UILabel alloc] initWithFrame:CGRectMake(label1’s x position from the 
     upper right corner, label1’s y position from the upper right corner, label1’s width, 
     label1’s height)]   
     _label1.font = [UIFont boldSystemFontOfSize:17]; 
     _label1.textAlignment = NSTextAlignmentLeft; 

     [self.contentView addSubview:_label1]; 
    } 
    return self; 
} 

這樣做是爲了您的標籤的每一個人,你是好去! :)

相關問題