自定義xib TableViewCell 標準寫法 代碼段

+ (CustonCell *)cellFromNibNamed:(NSString *)nibName

{

    NSArray *nibContents = [[NSBundlemainBundle] loadNibNamed:nibName owner:self options:NULL];

    NSEnumerator *nibEnumerator = [nibContentsobjectEnumerator];

    KIPullToRevealCell *customCell = nil;

    NSObject* nibItem = nil;

    while ((nibItem = [nibEnumerator nextObject]) != nil)

    {

        if ([nibItem isKindOfClass:[KIPullToRevealCellclass]])

        {

            customCell = (CustonCell *)nibItem;

            break;

        }

    }

    return customCell;

}



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

{

    static NSString *stCellIdentifier =@"Cell";

    CustonCell *cell = (CustonCell *)[tableViewdequeueReusableCellWithIdentifier:stCellIdentifier];

    

    if(!cell)

        cell = (CustonCell *)[CustonCellcellFromNibNamed:NSStringFromClass([CustonCellclass])];



    

    return cell;

}


發佈了404 篇原創文章 · 獲贊 65 · 訪問量 115萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章