SORU
8 Ocak 2013, Salı


İddia UİTableViewController içinde UİSearchDisplayController kullanırken arıza

Basit Arama uygulamam bir TableViewController işlevsellik eklemek için çalışıyorum. Ray Wenderlich öğretici takip ettim. Bazı veriler içeren bir tableView var, Hızlı Arama, arama çubuğuna ekran denetleyicisi ekledim, ve daha sonra bu kod var:

#pragma mark - Table View
     - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"BreedCell" forIndexPath:indexPath];

        //Create PetBreed Object and return corresponding breed from corresponding array
        PetBreed *petBreed = nil;

        if(tableView == self.searchDisplayController.searchResultsTableView)
            petBreed = [_filteredBreedsArray objectAtIndex:indexPath.row];
        else
            petBreed = [_breedsArray objectAtIndex:indexPath.row];

        cell.accessoryType  = UITableViewCellAccessoryDisclosureIndicator;
        cell.textLabel.text = petBreed.name;

        return cell;
    }

#pragma mark - Search
    -(BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString {
        [_filteredBreedsArray removeAllObjects];
        NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF.name contains[c] %@",searchString];
        _filteredBreedsArray = [[_breedsArray filteredArrayUsingPredicate:predicate] mutableCopy];

        return YES;
    }

    -(BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchScope:(NSInteger)searchOption {
        // Tells the table data source to reload when scope bar selection changes

        [_filteredBreedsArray removeAllObjects];
        NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF.name contains[c] %@",self.searchDisplayController.searchBar.text];
        _filteredBreedsArray = [[_breedsArray filteredArrayUsingPredicate:predicate] mutableCopy];
        return YES;
    }

Standart şeyler, ama metin girdiğimde arama çubuğunda bu hata ile her zaman çöküyor

2013-01-07 19:47:07.330 FindFeedo[3206:c07] *** Assertion failure in -[UISearchResultsTableView dequeueReusableCellWithIdentifier:forIndexPath:], /SourceCache/UIKit_Sim/UIKit-2372/UITableView.m:4460
2013-01-07 19:47:07.330 FindFeedo[3206:c07] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'unable to dequeue a cell with identifier BreedCell - must register a nib or a class for the identifier or connect a prototype cell in a storyboard'

Anladım ki iOS 6 kullanım ve dequeueing sistemi için hücreler değişti, ve aynı zamanda arama kullanır farklı bir tableView, ben de öyle düşünmüştüm sorun olduğunu arama tableView ile filtrelenmiş sonuçlar tam olarak anlayamadım hücre yatırdım bu benim viewDidLoad:

[self.searchDisplayController.searchResultsTableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"BreedCell"];

Ve voila! İşe yaradı... Sadece ilk kez arama. Orijinal sonuçlarına geri dön ve tekrar arama eğer, app aynı hata ile çöküyor. Belki de tüm ekleme hakkında düşündüm

if(!cell){//init cell here};

cellForRow yöntemine şeyler, ama dequeueReusableCellWithİdentifier sahip bütün amacı karşı gitmez:forİndexPath: yöntem? Her neyse, ben kayboldum. Neyi kaçırıyorum? Yardım, lütfen. Her zaman için şimdiden size (: . teşekkürler

Alex.

CEVAP
8 Ocak 2013, Salı


Kendi kendine kullanmayı deneyin.dequeueReusableCellWithİdentifier içinde tableView yerine tableView:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"BreedCell"];

    //Create PetBreed Object and return corresponding breed from corresponding array
    PetBreed *petBreed = nil;

    if(tableView == self.searchDisplayController.searchResultsTableView)
        petBreed = [_filteredBreedsArray objectAtIndex:indexPath.row];
    else
        petBreed = [_breedsArray objectAtIndex:indexPath.row];

    cell.accessoryType  = UITableViewCellAccessoryDisclosureIndicator;
    cell.textLabel.text = petBreed.name;

    return cell;
}

Bu kod gayet iyi çalışıyor

Not

Eğer özel yükseklik hücreleri varsa, kullanmayın

[self.tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

Bunun yerine kullanın

[self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • boogie2988

    boogie2988

    6 NİSAN 2006
  • Study with Substance P

    Study with S

    31 Mayıs 2008
  • UCBerkeley

    UCBerkeley

    3 Mayıs 2006