iOS開發怎麼註冊xib自定義的UITableViewCell


方案一:

- (void)viewDidLoad {

    [_tableView registerClass:[TasteMoneyCell class] forCellReuseIdentifier:@"TasteMoneyCell"];

}

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

{

    static NSString *identifier = @"TasteMoneyCell";

    TasteMoneyCell *cell = (TasteMoneyCell *)[tableView dequeueReusableCellWithIdentifier:identifier];    

    [cell initWithData:_dataSourse[indexPath.row]];

    return cell;

}


方案二:

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

{

    static NSString *identifier = @"cell";

    TasteMoneyCell *cell = (TasteMoneyCell *)[tableView dequeueReusableCellWithIdentifier:identifier];

    if (!cell) {

        cell = [[TasteMoneyCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];

        

    }

    

    [cell initWithData:_dataSourse[indexPath.row]];

    

    return cell;

}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章