Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/113.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios -[UITableView\u configureCellForDisplay:forIndexPath:]中的断言失败,_Ios_Objective C_Iphone_Xcode_Uitableview - Fatal编程技术网

Ios -[UITableView\u configureCellForDisplay:forIndexPath:]中的断言失败,

Ios -[UITableView\u configureCellForDisplay:forIndexPath:]中的断言失败,,ios,objective-c,iphone,xcode,uitableview,Ios,Objective C,Iphone,Xcode,Uitableview,我是xcode新手,我试图使用自定义单元格在tableview中显示一些数据,我在-[UITableView\u configureCellForDisplay:forIndexPath:中获得***断言失败,错误。请有人给我指路。提前谢谢。我使用故事板创建UITableview 这是我的Viewcontroller.m代码 #import "ViewController.h" #import "CustomCell.h" @interface ViewController () {

我是xcode新手,我试图使用自定义单元格在tableview中显示一些数据,我在-[UITableView\u configureCellForDisplay:forIndexPath:中获得
***断言失败,错误。请有人给我指路。提前谢谢。我使用故事板创建UITableview

这是我的Viewcontroller.m代码

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

您永远不会创建一个单元,您只是尝试重用一个出列的单元。所以

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

我认为您应该编辑问题代码部分的格式。我无法在tableview单元格中加载profilehd和profileimg数据。没有收到任何错误,单元格为空。我想加载profilehd=[[NSArray alloc]initWithObjects:@“Name”,@“Email”,@“Skype”,nil];profileimg=[[NSArray alloc]initWithObjects:@“about_me_icon.png”,“email_icon.png”,“skype_icon.png”,nil];