2013-11-22 16 views
14

Ich verwende tableview Apples Lazy Loading-Code in meinem Projekt, aber mit Ausnahme im Projekt. Und Fehler ist - *** Assertion failure in -[UITableView _configureCellForDisplay:forIndexPath:], hier ist mein Code bitte help.Aber es funktioniert in anderen Projekt.Ich habe keine Delegiertenmethode.*** Assertionsfehler in - [UITableView _configCellForDisplay: forIndexPath:]

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
    { 
    static NSString *CellIdentifier = @"LazyTableCell"; 
    static NSString *PlaceholderCellIdentifier = @"PlaceholderCell"; 

    NSUInteger nodeCount = [self.entries count]; 

if (nodeCount == 0 && indexPath.row == 0) 
    { 
     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:PlaceholderCellIdentifier]; 
    cell.detailTextLabel.text = @"Loading…"; 

    return cell; 
    } 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

if (nodeCount > 0) 
{ 
    AppRecord *appRecord = [self.entries objectAtIndex:indexPath.row]; 

    cell.textLabel.text = appRecord.name; 


    if (!appRecord.appIcon) 
    { 
     if (self.mytable_view.dragging == NO && self.mytable_view.decelerating == NO) 
     { 
      [self startIconDownload:appRecord forIndexPath:indexPath]; 
     } 

     cell.imageView.image = [UIImage imageNamed:@"Placeholder.png"]; 
    } 
    else 
    { 
     cell.imageView.image = appRecord.appIcon; 
    } 

} 

return cell; 

} 

Antwort

26

Da cellForRowAtIndexPath kehrt ein nil Wert und dann wird configureCellForDisplay eine UITableViewCell erwartet. Das Storyboard oder XIB hat keine Zelle, die mit der von Ihnen angegebenen Zell-ID definiert ist. Überprüfen Sie besser die Schreibweise des Bezeichners.

1

CellIdentifier Ich wette, dass Ihre cellForRowAtIndexPath Null zurückgibt.

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    static NSString *CellIdentifier = @"LazyTableCell"; 
    static NSString *PlaceholderCellIdentifier = @"PlaceholderCell"; 

    NSUInteger nodeCount = [self.entries count]; 
    if (nodeCount == 0 && indexPath.row == 0) { 
     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:PlaceholderCellIdentifier]; 
     if(cell == nil) 
     { 
      cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:PlaceholderCellIdentifier] autorelease]; 

     } 
     cell.detailTextLabel.text = @"Loading…"; 

     return cell; 

    } 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

    if(cell == nil) 
    { 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 
    } 

    if (nodeCount > 0) { 

     AppRecord *appRecord = [self.entries objectAtIndex:indexPath.row]; 

     cell.textLabel.text = appRecord.name; 


     if (!appRecord.appIcon) 
     { 
      if (self.mytable_view.dragging == NO && self.mytable_view.decelerating == NO) 
      { 
       [self startIconDownload:appRecord forIndexPath:indexPath]; 
      } 

      cell.imageView.image = [UIImage imageNamed:@"Placeholder.png"]; 
     } 
     else 
     { 
      cell.imageView.image = appRecord.appIcon; 
     } 

    } 

    return cell; 

} 

, die wahrscheinlich ist, warum [UITableView _configureCellForDisplay:forIndexPath:] ... versagt, weil cellForRowAtIndexPath wird einen Nullwert zurückkehrt und dann wird configureCellForDisplay eine UITableViewCell erwartet.

12

Bitte überprüfen Sie auf Delegieren.

Haben Sie beide Delegaten hinzugefügt oder nicht?

UITableViewDelegate, UITableViewDataSource

import UIKit 

class UserFriendVC: UIViewController, UITableViewDelegate, UITableViewDataSource 
{ 

    override func viewDidLoad() { 
     super.viewDidLoad() 
    } 
} 
3

Sie cellIdentifier von "Show die Attribute Inspektor" hinzufügen sollten. Bitte falle wie unten beschrieben.

Zuerst unten Code hinzugefügt, um Ihre -(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath Delagate-Methode.

-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ 

    ResultCustomTableViewCell *cell = (ResultCustomTableViewCell *)[resultTableView dequeueReusableCellWithIdentifier:@"ResultTableViewCellIdentifier"]; 

... 
//set the cell property 

... 
return cell; 
} 

und dann die "Show the attributes Inspector", während der ausgewählten Stammansicht der Zelle.

enter image description here

Und dann fügen Sie den gleichen Bezeichner Namen Kennung Abschnitt in „die Attribute Inspektor zeigen“. In diesem Fall verwende ich diesen ResultTableViewCellIdentifier.

Und noch ein Gedanke. Wenn Sie eine benutzerdefinierte Zelle wie dieses Szenario verwenden, müssen Sie unterhalb der Delegat-Methode hinzufügen. Weil Ihre benutzerdefinierte Zellenhöhe höher oder kleiner sein kann als die ursprüngliche Tabellenansicht. Und auch Sie sollten diese Spitze in viewDidLoad registrieren.

- (void)viewDidLoad { 
     [resultTableView registerNib:[UINib nibWithNibName:@"ResultCustomTableViewCell" bundle:nil] forCellReuseIdentifier:[ResultCustomTableViewCell reuseIdentifier]]; 

    } 


-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ 

       CGFloat height = 0.0; 

       if (tableView == resultTableView){ 
        height = 44.0f; 
       } 

       return height; 
      } 

ich hoffe, Ihr Problem beheben werde

Verwandte Themen