我做了一个表,取决于你点击你的哪个单元格将被发送到一个新的场景(detailviewcontroller)。例如,如果您单击具有文本泰国的单元格,您将被发送到ThailandDetailViewController(场景)。一切工作,直到你使用搜索栏(查看 - (无效)tableView)。塞格不工作,因为搜索栏
- 当一些国家(因为搜索功能)出现漏洞时,扩展国家将在表格中走高并获得较低的计数。这导致他们将导致错误的detailviewcontroller(场景)。
我的一个朋友对我说,我要我的阵列中使用objectAtIndex,真正地没有搭上了他的意思与..并就cell.textLabel.text开关(真正地没有跟随他)
这是我的.m文件:
- (void)viewDidLoad
{
[super viewDidLoad];
self.mySearchBar.delegate = self;
self.myTableView.delegate = self;
self.myTableView.dataSource = self;
totalStrings = [[NSMutableArray alloc] initWithObjects:@"America",@"Austria",@"Canada",@"France",@"Germany",@"Greece",@"Malaysia",@"Mexico",@"Netherlands",@"Poland",@"Russia",@"Singapore",@"Thailand",@"Ukraine", nil];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
switch (indexPath.row) {
case 0: [self performSegueWithIdentifier:@"Segue0" sender:self];
break;
case 1: [self performSegueWithIdentifier:@"Segue1" sender:self];
break;
//and so on
default: break;
}
}
-(void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
{
if(searchText.length == 0){
isFiltered = NO;
}
else
{
isFiltered = YES;
filteredStrings = [[NSMutableArray alloc]init];
for (NSString *str in totalStrings){
NSRange stringRange = [str rangeOfString:searchText options:NSCaseInsensitiveSearch];
if(stringRange.location !=NSNotFound) {
[filteredStrings addObject:str];
}
}
}
[self.myTableView reloadData];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *Cellidentifier = @"cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:Cellidentifier];
if (!cell) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:Cellidentifier];
}
if (!isFiltered) {
cell.textLabel.text = [totalStrings objectAtIndex:indexPath.row];
}
else //if it's filtered
{
cell.textLabel.text = [filteredStrings objectAtIndex:indexPath.row];
}
return cell;
}
非常感谢你预先!
非常感谢,只需要简单的一个问题就可以说下“现在你可以计算出什么类似的激活,如下所示:” – user3161418
不,这只是不好的格式:)现在看编辑版本,也许会让更多感觉这种方式:) – Janos