我有三个类,即DepartmentViewController,DepartmentRequest,Department。就像是从DepartmentViewcontroller发出部门请求,并基于响应来处理响应并在DepartmentRequest类中添加NSmutableArray * responseArray。该数组仅包含Department对象。我想要DepartmentViewController中的此responseArray用于搜索和重新加载tableview。所以我通过委托将该数组传递给DepartmentViewController,并将responseArray分配给localArray。现在我确实基于这两个数组进行搜索,但是如果我使用removeallobject删除了数组中的任何一个。它也删除了其他Array中的对象。
if(searchString.length>0)
{
[localArray removeAllObjects];
for (int i =0 ; i < [departmentRequest.responseArray count]; i++) {
Department *dept = [departmentRequest.responseArray objectAtIndex:i];
if (([dept.departmentName rangeOfString:searchString options:(NSCaseInsensitiveSearch|NSDiacriticInsensitiveSearch)].location != NSNotFound)
)
{
[localArray addObject:dept];
}
else{
NSLog(@"deptname %@",dept.departmentName);
}
}
[departmentTableView reloadData];
如果我在localArray中删除对象,则它在DepartmentReqeust.responseArray和localArray中都删除对象
最佳答案
你应该分配像
localArray = [NSArray arrayWithArray:responseArray];