简体   繁体   中英

How to use search bar in tableview using this code?

How to search cell.textLabel.text value with textfield ? 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
  2. Declare and initialize the UISearchDisplayController
  3. Add the searchBar to the your tableView
  4. Implement the UISearchDisplayController delegate methods

this popular link you get more idea

Adding UISearchBar Programmatically to UITableView

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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