我做了一個表,取決於你點擊你的哪個單元格將被髮送到一個新的場景(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