自定义cell的复用方式1
来源:互联网 发布:增城楼盘成交数据 编辑:程序博客网 时间:2024/05/29 04:10
首先我们导入plist文件,引入数据管理类。快速获取演示需要使用的数据模型。具体操作参考前一篇微博:
http://blog.csdn.net/lee727n/article/details/72584379
首先通过类方法获取数据模型的数据:
@interface NewsListTableViewController ()@property(nonatomic,strong)NSArray *allLists;@end@implementation NewsListTableViewController-(NSArray *)allLists { if(_allLists == nil) { _allLists = [DataManager allNewsLists]; } return _allLists;}
实现三问一答,使用第一种非注册复用方式。注意通过xib自定义的cell需要load nib
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1;}- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return self.allLists.count;}- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { ListCell *listCell = [tableView dequeueReusableCellWithIdentifier:@"listcell"]; if (!listCell) {/* 在当前应用程序中 找到 ListCell 这个xib 将 xib文件中所有的视图对象创建出来, 返回的是一个视图对象的数组 [[NSBundle mainBundle]loadNibNamed:@"ListCell" owner:nil options:nil] */ listCell = [[NSBundle mainBundle]loadNibNamed:@"ListCell" owner:nil options:nil].firstObject; } NewsList *newsList = self.allLists[indexPath.row]; listCell.newsTitleLabel.text = newsList.title; listCell.newsCommentCountLabel.text = [NSString stringWithFormat:@"%ld", newsList.commentCount]; listCell.newsImageView.image = [UIImage imageNamed:newsList.newsImage]; return listCell;}
效果如下:
阅读全文
0 0
- 自定义cell的复用方式1
- 自定义cell的复用方式2
- 自定义cell的三种方式
- IOS 自定义Cell的3种方式
- 自定义加载cell 两种靠谱的方式
- 使用Nib自定义Cell的复用
- tableview 自定义cell 点击cell改变cell中的label.text的字体颜色,cell复用出现问题
- tableview 自定义cell 点击cell改变cell中的label.text的字体颜色,cell复用出现问题
- 自定义cell 3中方式
- iOS——自定义cell的两种方式
- UICollectionViewCell中cell的定义与自定义方式总结
- 自定义等高cell和不等高cell的方式对比
- 自定义Cell的用法
- 自定义Cell的线条
- 自定义cell的frame
- 自定义cell的高度
- 自定义cell的用法
- 自定义cell的流程
- LeetCode566. Reshape the Matrix
- 校园招聘之算法编程题解析
- 12.struts2_表单标签
- SSM框架源码
- 程序员常见面试题之合并两个升序排列的链表
- 自定义cell的复用方式1
- recyclerView实现复杂布局的好处
- A-B Game
- CoInitializeSecurity function
- JavaScript的预解析
- 欢迎使用CSDN-markdown编辑器
- 在winform中使用进度条显示任务的执行进度
- Lua教程
- C# 参数关键字params的作用