ios tableView那些事 (十五)用故事模式自定义cell
2013-09-09 14:45
711 查看
如果想更灵活的添加一些数据我们常常自定义一个cell
先创建个工程 勾选sb 和arc
把默认的里面的viewcontr 删除,拖拽个tableviecontr
创建一个TableViewControllerTest 一个类,这时候我们要把 拖拽的视图和这个新建的类关联上
接下来我们新建一个继承 uitableviewcell 的类 celltest
下面我们吧这个类跟tableview关联上
点击视图上面的cell 并把新建的cell关联上! 如图在custom class 下面选择CellTest
把cell 的格式选择Custom 把Identifier 改成你cell 的类名
然后让我们托几个label吧
在tableview上在加几行代码就搞定了
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier =@"cell";
//CellTest *cell = (CellTest *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
CellTest *cell = (CellTest *)[tableViewdequeueReusableCellWithIdentifier:@"CellTest"];
if (cell == nil) {
cell = [[CellTestalloc]initWithStyle:UITableViewCellStyleSubtitlereuseIdentifier:CellIdentifier];
}
cell.label_one.text =@"one";
cell.label_second.text =@"second";
cell.labelthree.text =@"three";
return cell;
}
///////////////////////////////////14 年5.10///////////////////////////////////////////////////////
自定义一个tableview 后不显示数据,我排查了连接 委托是否有问题后,发现一切正常,后来看了下代码,发现我copy 的标识符GoodsCarTableViewCell 后面有了一个
空格,我把空格除去果断出现想要的数据,真是马虎呀。
GoodsCarTableViewCell *cell = (GoodsCarTableViewCell*) [tableView dequeueReusableCellWithIdentifier:@"GoodsCarTableViewCell
此处有空格 "]; 错误
正确
GoodsCarTableViewCell *cell = (GoodsCarTableViewCell*) [tableView dequeueReusableCellWithIdentifier:@"GoodsCarTableViewCell"];
后面无空格正确。
///////////////////////////////////14 年5.10///////////////////////////////////////////////////////
先创建个工程 勾选sb 和arc
把默认的里面的viewcontr 删除,拖拽个tableviecontr
创建一个TableViewControllerTest 一个类,这时候我们要把 拖拽的视图和这个新建的类关联上
接下来我们新建一个继承 uitableviewcell 的类 celltest
下面我们吧这个类跟tableview关联上
点击视图上面的cell 并把新建的cell关联上! 如图在custom class 下面选择CellTest
把cell 的格式选择Custom 把Identifier 改成你cell 的类名
然后让我们托几个label吧
在tableview上在加几行代码就搞定了
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier =@"cell";
//CellTest *cell = (CellTest *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
CellTest *cell = (CellTest *)[tableViewdequeueReusableCellWithIdentifier:@"CellTest"];
if (cell == nil) {
cell = [[CellTestalloc]initWithStyle:UITableViewCellStyleSubtitlereuseIdentifier:CellIdentifier];
}
cell.label_one.text =@"one";
cell.label_second.text =@"second";
cell.labelthree.text =@"three";
return cell;
}
///////////////////////////////////14 年5.10///////////////////////////////////////////////////////
自定义一个tableview 后不显示数据,我排查了连接 委托是否有问题后,发现一切正常,后来看了下代码,发现我copy 的标识符GoodsCarTableViewCell 后面有了一个
空格,我把空格除去果断出现想要的数据,真是马虎呀。
GoodsCarTableViewCell *cell = (GoodsCarTableViewCell*) [tableView dequeueReusableCellWithIdentifier:@"GoodsCarTableViewCell
此处有空格 "]; 错误
正确
GoodsCarTableViewCell *cell = (GoodsCarTableViewCell*) [tableView dequeueReusableCellWithIdentifier:@"GoodsCarTableViewCell"];
后面无空格正确。
///////////////////////////////////14 年5.10///////////////////////////////////////////////////////
相关文章推荐
- ios tableView那些事 (十五)用故事模式自定义cell
- ios tableView那些事 (十六) UITableView中Cell重用机制导致内容重复解决方法
- ios tableView那些事 (十四) 获取 tableview 每个cell 的坐标点
- ios tableView那些事(四)tableView添加标题,头尾和改变cell的宽度---tableview
- iOS开发中自定义tableView中某个cell的高度
- ios tableView那些事(四)tableView添加标题,头尾和改变cell的宽度
- IOS开发之TableView、多个TableViewCell、自定义Cell、Cell上画画(故事板+代码方式)
- iOS swift 自定义tableView不显示cell
- ios tableView那些事 (十六) UITableView中Cell重用机制导致内容重复解决方法
- iOS自定义cell,上下滚动tableView后,自定义cell会被打乱,甚至消失了
- IOS tableView通过代码自定义cell
- ios TableView那些事(三十 五)TableView 单选操作使用Autolayout实现UITableView的Cell动态布局和高度动态改变
- ios tableView那些事(四)tableView添加标题,头尾和改变cell的宽度
- iOS雨笙 lable自适应高度(多用于tableview的自定义cell中)
- iOS tableView 如何禁止滑动手势删除,只允许在编辑模式下进行删除Cell
- ios tableview 那些事(二十三) 解决headerView不随cell一起滚动的问题
- iOS开发——UI进阶篇(四)tableView的全局刷新,局部刷新,左滑操作,左滑出现更多按钮,进入编辑模式,批量删除,自定义批量删除
- ios tableView那些事 (十六) UITableView中Cell重用机制导致内容重复解决方法
- ios tableView那些事 (十六) UITableView中Cell重用机制导致内容重复解决方法
- ios tableView那些事 (十六) UITableView中Cell重用机制导致内容重复解决方法