I have tableview with searchDisplayController. When I search for some text I successfully display the results on screen. My problem arises when I want to add a cell to existing results. Adding a cell must be done when searchDisplayController is active.
That is:
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSMutableDictionary * dict ;
BOOL isSearchView = tableView == self.searchDisplayController.searchResultsTableView;
if (isSearchView) {
dict = [searchTasks objectAtIndex:indexPath.row];
[self.searchDisplayController.searchResultsTableView deselectRowAtIndexPath:indexPath
animated:YES];
}
else{
dict = [self.tasks objectAtIndex:indexPath.row];
[self.tableView deselectRowAtIndexPath:indexPath animated:YES];
}
Task * task = [self getsomeTask];
NSIndexPath * ip = [NSIndexPath indexPathForRow:indexPath.row+1
inSection:indexPath.section];
if (isSearchView) {
[searchTasks insertObject:task atIndex:ip.row];
[self.searchDisplayController.searchResultsTableView
insertRowsAtIndexPaths:@[ip]
withRowAnimation:UITableViewRowAnimationRight];
}
after this is executed, and after the last line insertRowsAtIndexPaths:@[ip]
,
the code executes:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (self.searchDisplayController.isActive) {
return [searchTasks count];
} else {
return [tasks count];
}
}
Which is fine and here it selects the first option which is true according to program logic. But the it crashed and after this execution it never calls
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
delegate function of UITableview.
And gives me error:
*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 1 beyond bounds [0 .. 0]'
I cannot understand the reason why it does not call the cellForRowAtIndexPath function after rowcount function.
Any suggestions?