The way the app works is pretty standard. I have a main table view with cells that contain an image and text. When I tap on an item, I am taken to a corresponding detail view made up of a UIWebView. The table can be searched. When I search the table, the results show up correctly. However, when I tap on an item from the search results, I am not taken to the correct detai开发者_JAVA百科l view. Instead, I am taken to the detail view of the item that existed in that row before searching.
What do I need to adjust/add so that the correct detail view is displayed when a search result is selected?
Sorry for not posting code; if you need to see something in particular, just let me know. Thanks!
UPDATED WITH CODE:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
MObjectDetailVC *mObjectDetailVC = [[MObjectDetailVC alloc] initWithNibName:@"MObjectDetailVC" bundle:nil];
mObjectDetailVC.detailURL = [[NSURL alloc] initWithString:[[mcData objectAtIndex:indexPath.row] url]];
mObjectDetailVC.title = [[mcData objectAtIndex:indexPath.row] name];
[self.navigationController pushViewController:mObjectDetailVC animated:YES];
[mObjectDetailVC release];
}
You should reform your array after you get the search results. Have two arrays: one array that contains the entire data and one searchResultArray that contains the data from the search query. If you are not searching keep the searchResultArray as NULL and keep showing the results as you are doing currently based on the original array. However as soon as a search is done and you get some results, populate the same in the searchResultArray. Now when you click a particular row, then in the didSelectRow method check if the searchArray is empty or not. If it is not empty then use this searchResultArray to populate the detail view.
May be you are retrieving the value from the old array.
Check your code that you are fetching the value from searched array.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[searchArray objectAtIndex:indexPath.row];
}
精彩评论