我有一个应用程序,当您使用搜索栏时,它会根据您输入的内容过滤患者,但是当您单击一行时,它总是在下一个 nib 文件中显示相同的数据。我知道这是因为 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];
}