表视图上的搜索栏(自定义tableview单元格)

时间:2011-10-10 09:43:30

标签: iphone

我正在实施一款iphone应用。我在其中使用自定义表格视图单元格实现了表格视图。在每个表格单元格中有7个标签。我想将搜索栏放在表格视图中。每当我尝试搜索One标签的值时,放置此标签的行整体不会出现在第一个位置,但标签值将被第一个标签的值替换。意思是说标签值不会影响整行。如何解决这个问题请给我一些解决方案。

非常感谢。

2 个答案:

答案 0 :(得分:0)

这是如何进行搜索栏的一个很好的例子:

https://github.com/erica/iOS-5-Cookbook/tree/master/C11/06-Searching%20Tables

处理表的创建和修改的所有代码都在主方法中:

https://github.com/erica/iOS-5-Cookbook/blob/master/C11/06-Searching%20Tables/main.m

答案 1 :(得分: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;
 }

对所有标签执行此操作,您就可以开始了! :)

相关问题