Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/119.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 我想将所选行保存在tableview中,并在搜索过程中对其进行维护_Ios_Objective C_Iphone_Uitableview_Cocoa Touch - Fatal编程技术网

Ios 我想将所选行保存在tableview中,并在搜索过程中对其进行维护

Ios 我想将所选行保存在tableview中,并在搜索过程中对其进行维护,ios,objective-c,iphone,uitableview,cocoa-touch,Ios,Objective C,Iphone,Uitableview,Cocoa Touch,这是我的密码,有人帮我吗? 在本例中,我显示项目列表,在搜索过程中,使用filterarray在表视图中显示搜索项目。 但我需要在重新加载表视图后的搜索过程中保持选择 #import "ViewController.h" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; // self.tableView.allow

这是我的密码,有人帮我吗? 在本例中,我显示项目列表,在搜索过程中,使用filterarray在表视图中显示搜索项目。 但我需要在重新加载表视图后的搜索过程中保持选择

#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

保留
NSIndexSet
NSMutableArray
。在每个
表视图上:didSelectRowAtIndexPath:
检查
索引集是否在数组中。
1.如果是,请将其拆下
2.如果没有,请添加它

重新加载tableView时,此数组不会更改