简体   繁体   English

如何使用此代码在TableView中使用搜索栏?

[英]How to use search bar in tableview using this code?

How to search cell.textLabel.text value with textfield ? 如何使用textfield搜索cell.textLabel.text值? I am using this code. 我正在使用此代码。

- (UITableViewCell *)tableView:(UITableView *)tableView
         cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil] autorelease];


cell.selectionStyle = UITableViewCellSelectionStyleNone;


UITextField* tf = nil ;
switch ( indexPath.row ) {
    case 0: {
        cell.textLabel.text = @"Name" ;
        tf = nameField_ = [self makeTextField:self.name placeholder:@"sathish"]; 
        [cell addSubview:nameField_];
        break ;
    }
    case 1: {
        cell.textLabel.text = @"Address" ;
        tf = addressField_ = [self makeTextField:self.address placeholder:@"example@gmail.com"];
        [cell addSubview:addressField_];
        break ;
    }
    case 2: {
        cell.textLabel.text = @"Password" ;
        tf = passwordField_ = [self makeTextField:self.password placeholder:@"Required"];
        [cell addSubview:passwordField_];
        break ;
    }
    case 3: {
        cell.textLabel.text = @"Description" ;
        tf = descriptionField_ = [self makeTextField:self.description placeholder:@"My Gmail Account"];
        [cell addSubview:descriptionField_];
        break ;
    }
}

tf.frame = CGRectMake(120, 12, 170, 30);    

[tf addTarget:self action:@selector(textFieldFinished:) forControlEvents:UIControlEventEditingDidEndOnExit];    

tf.delegate = self ;


    return cell;
}

Basic steps: 基本步骤:

  1. Declare and initialize UISearchBar in your class 在类中声明并初始化UISearchBar
  2. Declare and initialize the UISearchDisplayController 声明并初始化UISearchDisplayController
  3. Add the searchBar to the your tableView 将searchBar添加到您的tableView
  4. Implement the UISearchDisplayController delegate methods 实现UISearchDisplayController委托方法

this popular link you get more idea 这个流行的链接,你有更多的主意

Adding UISearchBar Programmatically to UITableView 以编程方式将UISearchBar添加到UITableView

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM