当我运行我的objective-c代码时,我面临本代码中的此错误

时间:2016-01-18 07:42:16

标签: ios objective-c uitableview

Assertion failure in -[UITableView _configureCellForDisplay:forIndexPath:], /SourceCache/UIKit_Sim/UIKit-2935.137/UITableView.m:6509
2016-01-18 12:35:16.816 ALJ Jobs[1008:60b] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:'
*** First throw call stack:

这是我在Objective-c编程中遇到问题的代码。

@implementation myCV

{

    NSMutableArray *CvArr;
    NSMutableArray *address;
}
-(void) viewDidLoad
{
    [super viewDidLoad];

    CvArr = [[NSMutableArray alloc] initWithObjects:@"My Cv_0",@"My Cv_1",@"My Cv_2",@"My Cv_3",@"My Cv_4", nil];

    address = [[NSMutableArray alloc] initWithObjects:@"Pakistan_0",@"Pakistan_1",@"pakistan_2",@"pakistan_3",@"pakistan_4",nil];

}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{

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

    return [CvArr count];
}

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

    NSString *reUseid=@"cellID";
    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:reUseid];
    if (cell==nil)
    {
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reUseid];

}    

    Cell.textLabel.text = [CvArr objectAtIndex:indexPath.row];
    return Cell;

}

1 个答案:

答案 0 :(得分:0)

尝试以下代码,希望它能解决您的问题。

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

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];

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

    cell.textLabel.text = [CvArr objectAtIndex:indexPath.row];
    return cell;
}

参考:iOS Programming Tutorial: Create a Simple Table View App