xib作为cell时的复用问题打赏

apple鼓励大家使用图形化界面开发,这样效率更高,但我们在使用xib新建cell的时候会遇到问题,xib新建时是没有initWithStyle: reuseIdentifier:这个方法的,但为了效率cell还是需要复用,所以就需要用下面方法来新建cell了:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
MyCustomCell * cell = [tableView dequeueReusableCellWithIdentifier:@"myCell"];
if (!cell){

    [tableView registerNib:[UINib nibWithNibName:@"MyCustomCell" bundle:nil] forCellReuseIdentifier:@"myCell"];
    cell = [tableView dequeueReusableCellWithIdentifier:@"myCell"];
}
return cell;
}