xib自定义uitablecell 的两种写法(uitableview custom cell from xib)
2012-12-08 16:42
387 查看
Method #1:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"HFCustomCell"];
if (cell == nil) {
// Create a temporary UIViewController to instantiate the custom cell.
UIViewController *temporaryController = [[UIViewController alloc] initWithNibName:@"HFCustomCell" bundle:nil];
// Grab a pointer to the custom cell.
cell = (BDCustomCell *)temporaryController.view;
[[cell retain] autorelease];
// Release the temporary UIViewController.
[temporaryController release];
}
return cell;
}
Method #2:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"HFCustomCell"];
if (cell == nil) {
// Load the top-level objects from the custom cell XIB.
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"HFCustomCell" owner:self options:nil];
// Grab a pointer to the first object (presumably the custom cell, as that's all the XIB should contain).
cell = [topLevelObjects objectAtIndex:0];
}
return cell;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"HFCustomCell"];
if (cell == nil) {
// Create a temporary UIViewController to instantiate the custom cell.
UIViewController *temporaryController = [[UIViewController alloc] initWithNibName:@"HFCustomCell" bundle:nil];
// Grab a pointer to the custom cell.
cell = (BDCustomCell *)temporaryController.view;
[[cell retain] autorelease];
// Release the temporary UIViewController.
[temporaryController release];
}
return cell;
}
Method #2:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"HFCustomCell"];
if (cell == nil) {
// Load the top-level objects from the custom cell XIB.
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"HFCustomCell" owner:self options:nil];
// Grab a pointer to the first object (presumably the custom cell, as that's all the XIB should contain).
cell = [topLevelObjects objectAtIndex:0];
}
return cell;
}
相关文章推荐
- UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath
- iOS开发:XIB之UITableView自定义cell
- UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:
- UITableView+FDTemplateLayoutCell xib demo 例子
- 一个UITableView两种Cell的实现
- 解决UItableView cell的间隔线 separatorStyle ( plain group 两种类型)
- How to get UITableView from UITableViewCell?
- UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath
- UI基础之UITableView案例团购----自定义cell利用xib
- Ios 自定义表示图出现的相关问题UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:'
- 'UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:
- 关于错误 reason: 'UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:'
- UITableView的两种重用Cell方法的区别
- [iOS]通过xib自定义cell的时候在awakeFromNib方法里面修改view的frame无效
- Swift编程(一):UITableView及自定义Cell的Xib
- Swift_ uitableview使用自定义(xib)cell
- UITableView的cell的两种动画效果。
- iOS UItableview的两种重用cell的方法的区别
- UITableView自动计算cell高度并缓存(Xib)
- UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath