Reputation: 1185
I have three class namely DepartmentViewController, DepartmentRequest, Department. Its like im making a department request from DepartmentViewcontroller and based on response im manipulating repsonse and adding in NSmutableArray *responseArray in DepartmentRequest class. This array just contains Department object. I want this responseArray in DepartmentViewController for searching and reloading tableview. so i passed this array to DepartmentViewController through delegate and assigning responseArray to localArray. Now I did searching based on these two array but if i remove any one of the array using removeallobject. Its removing object in other Array too.
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];
if i remove object in localArray its removing objects both in departmentReqeust.responseArray and localArray
Upvotes: 0
Views: 216
Reputation: 50
if(searchString.length>0) {
// [localArray removeAllObjects];
NSMutableArray arrTemp=[[NSMutableArray alloc]init];
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)
)
{
[arrTemp addObject:dept];
}
else{
NSLog(@"deptname %@",dept.departmentName);
}
}
localArray = [NSArray arrayWithArray:arrTemp];
[departmentTableView reloadData];
Upvotes: 0
Reputation: 1702
You should assign like
localArray = [NSArray arrayWithArray:responseArray];
Upvotes: 5