如何停止在自定义单元格中重新加载数据?

时间:2016-01-05 14:23:32

标签: objective-c

在我的自定义单元格数据中将重新加载如何停止该数据?

这是我的自定义单元格代码

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    [![enter image description here][1]][1]{
    static NSString *CellIdentifier = @"Cell";
    ContestTableViewCell *cell = [myContestTableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil) {
        NSArray *myNib;
        myNib =[[NSBundle mainBundle]loadNibNamed:@"ContestTableViewCell" owner:self options:nil];
        cell =[myNib objectAtIndex:0];
    }

    if (selectedIndex==indexPath.row) {

    } else {

    }

    cell.fldExamTitleLbl.text = [fldExamTitleArray objectAtIndex:indexPath.row];
    cell.fldExamStartDateLbl.text = [fldExamStartArray objectAtIndex:indexPath.row];
    cell.prizeMoney.text =[prizeMoneyArray objectAtIndex:indexPath.row];
    cell.firstReward.text = [firstRewardArray objectAtIndex:indexPath.row];
    cell.secondReward.text = [secondRewardArray objectAtIndex:indexPath.row];
    cell.thirdReward.text = [thirdRewardArray objectAtIndex:indexPath.row];

    return cell;
}

屏幕将显示如下

1 个答案:

答案 0 :(得分:1)

你做得不对。您应该加载一次nib,然后在表视图中注册它以获得可重用的标识符。最好在加载子视图后在viewDidLoad或其他构造函数中完成此操作:

[[NSBundle mainBundle] loadNibNamed:@"MyCellNib" owner:self options:nil];
[self.tableView registerNib:[UINib nibWithNibName:@"MyCellNib" bundle:nil] forCellReuseIdentifier:@"myCellIdentifier"];

单元格标识符可以是您想要的任何内容,但在将单元格出列时使用相同的标识符。