我有一個應用程序,當您使用搜索欄時,根據您放入的內容來過濾患者,但當您單擊某一行時,它總是會在下一個nib文件中顯示相同的數據。我知道這是因爲indexPath是隨着單元格順序的改變而改變的,而它們的數量有沒有辦法讓它走向正確的呢?搜索已過濾的數組索引路徑不正確
IndexPath代碼:
- (void)tableView:(UITableView *)tv didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
LSAppDelegate *delegate = (LSAppDelegate *)[[UIApplication sharedApplication] delegate];
PatientController *patient = [[PatientController alloc] initWithIndexPath:indexPath];
[delegate.navController pushViewController:patient animated:YES];
[tv deselectRowAtIndexPath:indexPath animated:YES];
}
搜索代碼:
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText {
if (searchText.length == 0) {
isFiltered = NO;
} else {
isFiltered = YES;
filteredPatients = [[NSMutableArray alloc] init];
for (Patient *patient in patients) {
NSRange patientNameRange = [[patient.patientName substringToIndex:1] rangeOfString:searchText options:NSCaseInsensitiveSearch];
if (patientNameRange.location != NSNotFound) {
[filteredPatients addObject:[NSString stringWithFormat:@"%@ %@", patient.patientName, patient.patientSurname]];
}
}
}
[self.tableView reloadData];
}
訪問包含導航控制器您的問題有點含糊。您能否詳細說明並顯示一些您正在使用的索引路徑的代碼? –
@XCodeMonkey添加了代碼 – Hive7