2013-11-22 16 views
14

Tôi đang sử dụng mã tải lười biếng của tableview apple trong dự án của tôi, nhưng có ngoại lệ trong dự án. Và lỗi là - *** Assertion failure in -[UITableView _configureCellForDisplay:forIndexPath:], đây là mã của tôi xin vui lòng help.But nó đang làm việc trong project.I khác không có phương pháp đại biểu.*** Lỗi xác nhận trong - [UITableView _configureCellForDisplay: 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; 

} 

Trả lời

26

cellForRowAtIndexPath được trả lại một giá trị nil và sau đó configureCellForDisplay đang mong đợi một UITableViewCell. Bảng phân cảnh hoặc XIB không có ô được xác định bằng số nhận dạng ô bạn đã chỉ định. Kiểm tra tốt hơn chính tả của số nhận dạng.

1

CellIdentifier Tôi đặt cược cellForRowAtIndexPath của bạn đang trở lại không.

-(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; 

} 

Đó có thể là lý do tại sao [UITableView _configureCellForDisplay:forIndexPath:] là không ... vì cellForRowAtIndexPath được trả lại một giá trị null và sau đó configureCellForDisplay đang mong đợi một UITableViewCell.

12

Vui lòng kiểm tra Đại biểu.

Bạn đã thêm cả hai đại biểu chưa?

UITableViewDelegate, UITableViewDataSource

import UIKit 

class UserFriendVC: UIViewController, UITableViewDelegate, UITableViewDataSource 
{ 

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

bạn nên thêm cellIdentifier từ "Hiển thị các thuộc tính thanh tra". Xin vui lòng bỏ rơi giống như đoạn dưới đây.

Trước tiên được thêm mã bên dưới vào phương thức delagate -(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath của bạn.

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

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

... 
//set the cell property 

... 
return cell; 
} 

và sau đó nhảy "Hiển thị thanh tra thuộc tính", Trong khi chọn chế độ xem gốc của ô đã chọn.

enter image description here

Và sau đó dán tên định danh tương tự cho phần định danh trong "Hiển thị các thuộc tính thanh tra". trong trường hợp này tôi sử dụng ResultTableViewCellIdentifier này.

Và một ý tưởng khác. nếu bạn sử dụng ô tùy chỉnh giống như trường hợp này, bạn phải thêm dưới đây metod đại biểu. Bởi vì chiều cao ô tùy chỉnh của bạn có thể cao hơn hoặc nhỏ hơn chiều cao tableview ban đầu. Và Ngoài ra, bạn nên đăng ký nib này trong viewDidLoad.

- (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; 
      } 

tôi hy vọng nó sẽ khắc phục được sự cố của bạn

Các vấn đề liên quan