自定义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];