【发布时间】:2017-11-16 00:34:24
【问题描述】:
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:
(NSIndexPath *)indexPath
{
if (indexPath.row == 0) {
[self performSegueWithIdentifier:@"hello" sender:self];
}
if (indexPath.row == 1) {
[self performSegueWithIdentifier:@"hello1" sender:self];
}
这是我用来执行转场以转到指定的视图控制器的方法。但是,我已经实现了一个搜索栏。搜索栏过滤某些单元格并重新排序。因此,不同的单元格指向不同的视图控制器。如果我在搜索栏中搜索“hello1”,它将在 tableview 中显示“hello1”作为第一个,并且不会显示“hello”。但是由于 "hello" 设置为 indexPath.row == 0,在应用程序中点击 "hello1" 将执行 "hello" segue,而不是 "hello1" segue。我怎样才能解决这个问题?非常感谢任何帮助。
我的搜索条码:
-(void) searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText {
NSLog(@"clicked!");
if ([searchText length] == 0) {
[_results removeAllObjects];
[_results addObjectsFromArray:_testphrases];
} else {
[_results removeAllObjects];
for (NSString * string in _testphrases) {
NSRange r = [string rangeOfString:searchText options: NSCaseInsensitiveSearch];
if (r.location != NSNotFound) {
[_results addObject:string];
}
}
}
[tableView reloadData];
}
(_results 是 _resultsArray,_testphrases 是 _masterArray)
新的搜索条码:
-(void) searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText {
NSLog(@"clicked!");
if ([searchText length] == 0) {
[_results removeAllObjects];
[_results addObjectsFromArray:_testphrases];
} else {
[_results removeAllObjects];
for (NSDictionary * string in _testphrases) {
for (NSString *key in string) {
NSString *value = [string objectForKey:key];
NSRange r = [value rangeOfString:searchText options: NSCaseInsensitiveSearch];
if (r.location != NSNotFound) {
[_results addObject:string];
}}
}
}
[tableView reloadData];
}
这是搜索发生时的样子: http://imgur.com/a/jpvBi
【问题讨论】:
标签: ios objective-c iphone xcode uitableview