UITableView之(四):使用UITableViewCell
2016-09-12 10:24
399 查看
创建使用tableViewCell有两种方式:
1、创建tableViewCell:常应用于代码创建
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *const cellId = @"cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:(UITableViewCellStyleSubtitle) reuseIdentifier:cellId];
}
// 设置cell的相关属性
return cell;
}
2、注册tableViewCell:常应用于Xib/StoryBoard创建
在创建tableView的时候就进行cell的注册:
[self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:cellId]; // 代码创建
[self.tableView registerNib:[UINib nibWithNibName:@"创建xib设置的控件名" bundle:nil] forCellReuseIdentifier:cellId]; // xib创建
使用注册创建tableViewCell,tableView的代理方法中,获取可重用的tableViewCell使用如下方法:
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId forIndexPath:indexPath];
1、创建tableViewCell:常应用于代码创建
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *const cellId = @"cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:(UITableViewCellStyleSubtitle) reuseIdentifier:cellId];
}
// 设置cell的相关属性
return cell;
}
2、注册tableViewCell:常应用于Xib/StoryBoard创建
在创建tableView的时候就进行cell的注册:
[self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:cellId]; // 代码创建
[self.tableView registerNib:[UINib nibWithNibName:@"创建xib设置的控件名" bundle:nil] forCellReuseIdentifier:cellId]; // xib创建
使用注册创建tableViewCell,tableView的代理方法中,获取可重用的tableViewCell使用如下方法:
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId forIndexPath:indexPath];
相关文章推荐
- 使用storyboard显示UITableView时,如果不修改系统默认生成的tableView:cellForRowAtIndexPath:方法中的代码,则必须为UITableViewCell注册(填写)重用标识符:identifier.必须要代码方法中的标识符一致.
- iOS之UITableView的使用——自定义UITableViewCell
- UITableView和UITableViewCell的一点使用小总结
- 使用UITableView的自定义UITableViewCell构建聊天界面
- iOS-UITableView和UITableViewCell的使用
- iphone开发之表格组件UITableView的使用(五)UITableView与UItableViewCell常见属性以及单元格重用
- UITableView 基本使用方法总结
- UITableView使用大全-表视图合集-持续更新
- UITableView 基本使用方法总结
- UITableView 基本使用方法总结
- UITableViewCell - UITableView中cell的边框和背景
- UITableView 基本使用方法总结
- UITableView 使用心得
- 使用UIAlertView和UITableView来创建一个有用的UIAlertTableView
- iphone UITableView及UIWebView的使用
- iphone UITableView及UIWebView的使用
- 第一、UITableView的使用大全
- UITableView使用方法
- UITableView delegate的使用
- 转载:使用UITableView实现树视图