自定義UITableViewCell

自定義UITableViewCell
有三種方式自定義單元格: XIB Storyboard 代碼 注意: 經過XIB或者Storyboard自定義單元格時,須要指定單元格的可重用標示符 若是使用XIB方式,須要在viewDidload方法中,註冊XIB文件 UINib
*nib = [UINib nibWithNibName:@」bookCell" bundle:[NSBundle mainBundle]]; [self.tableView registerNib:nib forCellReuseIdentifier:@」cell"];

 

UITableView性能優化補充

1. 在Storyboard中直接自定義單元格會註冊單元格原型
2. 用XIB方式自定義單元格須要註冊NIB
UINib *nib = [UINib nibWithNibName:@」bookCell" bundle:[NSBundle mainBundle]];
[tableView registerNib:nib forCellReuseIdentifier:@」cell"];
3. 用代碼方式自定義單元格須要註冊類
[tableView registerClass:[MyCell class] forCellReuseIdentifier:CellIdentifier];

如下方法的目的就是要求必需要註冊自定義單元格類
[tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
相關文章
相關標籤/搜索