第一種,加載xib中Cell,需要在xib頁面設(shè)置identifier,否則每次都會重新創(chuàng)建抬驴。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
YXStoreTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"YXStoreTableViewCell"];
if (!cell) {
cell = [[NSBundle mainBundle]loadNibNamed:@"YXStoreTableViewCell" owner:self options:nil].firstObject;
}
cell.model = storeArr[indexPath.section];
return cell;
}
第二種炼七,使用tableview自帶方法,配置registerNIb布持,即可實現(xiàn)重用豌拙。無需在xib頁面中設(shè)置identifier。
注意:如果在xib頁面中設(shè)置了identifier题暖,則必須與代碼中的identifier保持一致按傅。否則崩潰,提示:(reason: 'cell reuse indentifier in nib (YXStoreTableViewCell1) does not match the identifier used to register the nib (YXStoreTableViewCell)')
[self.tableView registerNib:[UINib nibWithNibName:@"YXStoreTableViewCell" bundle:nil] forCellReuseIdentifier:@"YXStoreTableViewCell"];
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
YXStoreTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"YXStoreTableViewCell"];
cell.model = storeArr[indexPath.section];
return cell;
}