简体   繁体   中英

Assertion failure in -[UITableView _configureCellForDisplay:forIndexPath:],

Am new to xcode am trying to display some data in tableview using custom cell am getting *** Assertion failure in -[UITableView _configureCellForDisplay:forIndexPath:] ,error. Please can anybody guide me. Thanks in advance. Am using storyboard for creating UITableview.

Here is my Viewcontroller.m code

#import "ViewController.h"
#import "CustomCell.h"
@interface ViewController ()

{
    NSArray *profilehd;
    NSArray *profileimg;
}

@end

@implementation ViewController

@synthesis tableview;

-(void)viewDidLoad
{
    tablevw.dataSource = self;
    tablevw.delegate = self;

    profilehd = [[NSArray alloc]initWithObjects:@"Name",@"Email",@"Skype", nil];
    profileimg = [[NSArray alloc]initWithObjects:@"about_me_icon.png",@"email_icon.png",@"skype_icon.png", nil];

    [super viewDidLoad];

    // Do any additional setup after loading the view, typically from a nib.
}


#pragma mark:-UITableView Datasource and Delegate Methods

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [profilehd count];
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellIdentifier = @"CellID";

    CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];

    if (cell == nil)
    {
        cell.ProfilehdLabel.text = [profilehd objectAtIndex:indexPath.row];
        cell.profileImgvw.image = [UIImage imageNamed:[profileimg objectAtIndex:indexPath.row]];
      }

    return cell;
}

CustomCell.m

@property (strong, nonatomic) IBOutlet UILabel *profilehdLabel;
@property (strong, nonatomic) IBOutlet UIImageView *profileImgvw;

you are never creating a cell, you just try to reuse a dequeued cell. so,

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
{
    static NSString *cellIdentifier = @"CellID";
    CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (!cell) {
       // if cell is empty create the cell
        cell = [[CustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    }

   cell.ProfilehdLabel.text = [profilehd objectAtIndex:indexPath.row];

cell.profileImgvw.image = [UIImage imageNamed:[profileimg objectAtIndex:indexPath.row]];

    return cell;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM