IPhone : I want to save the selected rows in tableview and during searching it will maintain it

on Wednesday, February 25, 2015

here my code,someone help me.


import "ViewController.h"


@interface ViewController ()


@end


@implementation ViewController




  • (void)viewDidLoad {


    [super viewDidLoad];


    // self.tableView.allowsMultipleSelection = YES;


    _button=[[UIButton alloc]init];


    _tableListArray=[NSMutableArray arrayWithObjects:@"Suresh kumar",@"Nanda kumar",@"Cheese",@"Jam",@"Pizza",@"Burger",@"Roll Pizza",@"Butter Bread",@"Bread",nil];


    _filteredListArray=[[NSMutableArray alloc]initWithArray:_tableListArray];


    NSLog(@"fiter=>%@",_filteredListArray) ;




}


-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {


// return [_tableListArray count]; return 1;


}


-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section


{



//return [_tableListArray count];
return [_filteredListArray count];


}


-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath


{



static NSString *cellIdentifier=@"Cell";
UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell==nil) {
cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];

}

cell.textLabel.text=[_filteredListArray objectAtIndex:indexPath.row];
NSLog(@"filterarray=>%@",_filteredListArray);

return cell;


}


-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath


{


// i want to know what can i do here


}


pragma mark-TextFieldDelegate


-(BOOL)textFieldShouldReturn:(UITextField *)textField


{



[textField resignFirstResponder];

return YES;


}


-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string


{



_textFld.text = [textField.text stringByReplacingCharactersInRange:range withString:string];

NSLog(@"textfield%@",_textFld);

NSString *myString=_textFld.text;


if (myString.length==0) {

_filteredListArray=_tableListArray;

}

else
{


NSPredicate *predicate=[NSPredicate predicateWithFormat:@"self contains[cd] %@",myString];


_filteredListArray=[NSMutableArray arrayWithArray:[_tableListArray filteredArrayUsingPredicate:predicate]];



}


[_tableView reloadData];



return NO;


}


@end


0 comments:

Post a Comment