使用initwithstyle方法初始化UITableViewCell

时间:2015-03-22 07:27:06

标签: uitableview

任何人都可以在初始化UITableViewCell时向我解释这里发生了什么。提前谢谢

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        NSArray *nibArray=[[NSBundle mainBundle]loadNibNamed:@"CustomCell" owner:nil options:nil];
        self=[nibArray objectAtIndex:0];
    }
    return self;
}

1 个答案:

答案 0 :(得分:0)

试试这个


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CustomCell"];
    if (cell == nil) {
        // Load the nib array from the custom cell XIB.
        NSArray *nibArray = [[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil];
        // Grab a pointer to the first object 
        cell = [nibArray objectAtIndex:0];
    }
   //set cell data

return cell;

}