【问题标题】:search bar on table view (custom tableview cell)表格视图上的搜索栏(自定义表格视图单元格)
【发布时间】:2011-10-10 09:43:30
【问题描述】:

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

非常感谢。

【问题讨论】:

    标签: iphone


    【解决方案1】:

    这是一个非常棒的搜索栏示例:

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

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

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

    【讨论】:

      【解决方案2】:

      当我不久前遇到这个问题时,我偶然看到了一篇关于搜索栏的文章: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;
       }
      

      对您的每个标签都执行此操作,您就可以开始了! :)

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-02-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多