在目标c中从NSMutableArray中获取错误的ID

我是iOS新手,当我search后在我的文本框中添加search框给我错误的ID。 在我的代码中有三个数组,一个是id,另一个是名字,第三个是search。

我的代码:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)sections{ if(tableView == table) { if(isFilter) { return [searchArray count]; } else return [idarray count]; } } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { if(tableView == table) { if(isFilter) { cell.textLabel.text=[NSString stringWithFormat:@"%@",[searchArray objectAtIndex:indexPath.row]]; } else { cell.textLabel.text=[NSString stringWithFormat:@"%@",[namearray objectAtIndex:indexPath.row]]; } } } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { if(tableView == table) { if(isFilter) { txt.text=[searchArray objectAtIndex:indexPath.row]; table.hidden=YES; txt.enabled=NO; txt.text=[NSString stringWithFormat:@"%@",[namearray objectAtIndex:indexPath.row]]; idlbl.text=[NSString stringWithFormat:@"%@",[idarray objectAtIndex:indexPath.row]]; EmployeeID=idlbl.text; EmployeeName=txt.text; } else { txt.text=[NSString stringWithFormat:@"%@",[namearray objectAtIndex:indexPath.row]]; idlbl.text=[NSString stringWithFormat:@"%@",[idarray objectAtIndex:indexPath.row]]; table.hidden=YES; EmployeeID=idlbl.text; EmployeeName=txt.text; txt.enabled=NO; } } } -(void)textFieldDidChange:(UITextField *)textField { searchTextString=textField.text; [self updateSearchArray:searchTextString]; } -(void)updateSearchArray:(NSString *)searchText { if(searchText.length==0) { isFilter=NO; } else{ isFilter=YES; searchArray=[[NSMutableArray alloc]init]; for(NSString *string in namearray){ NSRange stringRange=[string rangeOfString:searchText options:NSCaseInsensitiveSearch]; if(stringRange.location !=NSNotFound){ [searchArray addObject:string]; } } [table reloadData];} } 

我将EmployeeID设置为1,其中EmployeeID为18它取的表中的值不是取得id数组的值。 我使用if(tableview ==表),因为在一个视图控制器中有多个表。 在这里输入图像说明 它也在更新id。 如图所示 在这里输入图像说明

但是我不需要更新idarray。 我的问题是我怎么能得到数组的价值,它给了我一个tableview单元格的索引path任何Suggetion在此先感谢!

当我用我的应用程序中的search栏button工作时,我也得到了同样的问题,但我已经创build了文本框,充当search栏。

我认为这也会为你工作,快乐编码…….

点击这里

选中此文件以创build一个数组,然后使用NSPredicate在该数组上执行search

https://gist.github.com/himanshu-benzatine/716fd8d7ca035a5c0a01c87df48915bf