tableview 重用nib cell
#import "ViewController.h"
#import "NewsTableViewCell.h" #define UISCREEN_HEIGHT ([UIScreen mainScreen].bounds.size.height)
#define UISCREEN_WIDTH ([UIScreen mainScreen].bounds.size.width)
@interface ViewController ()<UITableViewDataSource,UITableViewDelegate> @property (nonatomic, strong) UITableView * tableView;
@end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad]; if ([self tableView]) {
//一定先要注册class 再注册 nib
[self.tableView registerClass:[NewsTableViewCell class] forCellReuseIdentifier:@"NewsTableViewCell"];
UINib * nib = [UINib nibWithNibName:@"NewsTableViewCell" bundle:nil];
[self.tableView registerNib:nib forCellReuseIdentifier:@"NewsTableViewCell"];
}
// Do any additional setup after loading the view, typically from a nib.
}
-(UITableView *)tableView
{
if (!_tableView) {
_tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, UISCREEN_WIDTH, UISCREEN_HEIGHT) style:UITableViewStylePlain];
_tableView.backgroundColor = [UIColor clearColor];
_tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
_tableView.delegate = self;
_tableView.dataSource = self; [self.view addSubview:_tableView];
}
return _tableView;
} -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 10;
} -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 120;
} -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"NewsTableViewCell" forIndexPath:indexPath];
// if (!cell) {
// cell = [[[NSBundle mainBundle] loadNibNamed:@"NewsTableViewCell" owner:self options:nil] lastObject];
// }
return cell;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} @end
tableview 重用nib cell的更多相关文章
- 动态切换tableView中的cell的种类
动态切换tableView中的cell的种类 为什么要动态切换tableView中cell的种类呢?如果项目经理不出这种需求,你也就见不到这篇文章了:) 效果: 源码: 首先,你要准备3种cell,直 ...
- Swift - 设置tableView每个分区cell圆角
1.// 重新绘制cell边框 func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRow ...
- iOS中关于动态Tableview中的cell数据传输的多线程问题解决之拙见
iOS中关于动态Tableview中的cell数据传输的多线程问题解决之拙见 (2015-12-05 12:48:20)[编辑][删除] 转载▼ 首先我们先明确一下问题: 1.因为UI是在主线 ...
- 更新tableView的某个cell
更新tableView的某个cell 异步加载完数据后更新某个cell,这应该是非常常见的使用方法了,我们经常会用reloadData. 效果: 源码: // // RootViewControlle ...
- 优化tableView加载cell与model的过程
优化tableView加载cell与model的过程 效果图 说明 1. 用多态的特性来优化tableView加载cell与model的过程 2. swift写起来果然要比Objective-C简洁了 ...
- 使用HVTableView动态展开tableView中的cell
使用HVTableView动态展开tableView中的cell 效果: 源码: HVTableView.h 与 HVTableView.m // // HVTableView.h // HRVTab ...
- ios中自定义tableView,CollectionView的cell什么时候用nib加载,什么时候用标识重用
做了一段时间的iOS,在菜鸟的路上还有很长的路要走,把遇到的问题记下来,好记性不如烂笔头. 在项目开发中大家经常会用到tableView和collectionView两个控件,然而在cell的自定义上 ...
- iOS中UITableView数据源刷新了,但tableview当中的cell没有刷新
你会不会遇到通过断点查看数据源模型的确刷新了,但是tableview没有刷新的情况,我遇到了,并通过下面的方法解决了,供大家参考! 在tableview中的数据源代理方法 p.p1 { margin: ...
- 在tableView中设置cell的图片和文字
// 设置UITableViewCellEditingStyle的 accessoryType UITableViewCellAccessoryNone, // d ...
随机推荐
- head first-----decorate design pattern
浅谈设计模式之------装饰者模式 首先给出装饰者模式的定义吧: 动态的将责任附加到对象上,若是要扩展功能,装饰者提供了比继承更加具有弹性的替代方案. 其中 ...
- 获取文件CRC和MD5
unit untCRCMD5; interface { 获取文件CRC校验码 } function GetFileCRC(const iFileName: string): String; { 获取字 ...
- 淘宝分布式数据层:TDDL[转]
淘宝根据自己的业务特点开发了TDDL(Taobao Distributed Data Layer 外号:头都大了 ©_Ob)框架,主要解决了分库分表对应用的透明化以及异构数据库之间的数据复制,它是一个 ...
- SSD -----TLC MLC SLC
SLC缓存什么鬼?TLC评测造假要持续多久 2016.5.5来源:中关村在线 TLC的廉价真的将SSD引入了全面普及的高速公路上,谈到TLC我们更多的理解是TLC的P/E(Program/Erase ...
- iOS-UICollectionView自定义布局
UICollectionView自定义布局 转载: http://answerhuang.duapp.com/index.php/2013/11/20/custom_collection_view_l ...
- android开发之调试技巧 分类: android 学习笔记 2015-07-18 21:30 140人阅读 评论(0) 收藏
我们都知道,android的调试打了断点之后运行时要使用debug as->android application 但是这样的运行效率非常低,那么我们有没有快速的方法呢? 当然有. 我们打完断点 ...
- Robolectric Test-Drive Your Android Code
Running tests on an Android emulator or device is slow! Building, deploying, and launching the app o ...
- Block之变量作用域
在使用block的过程中经常会调用不同类型.不同作用域的变量,如果对这些变量作用域的理解稍有偏差,就会出现问题.故此特意整理出block中会经常使用到的几种变量,如有补充,欢迎指出. 1. 局部变量 ...
- javascript新的原生态API
以下是最新的w3c标准的javascript,目前支持运行在firefox, chrome,IE9以上版本的浏览器 参考资料:https://developer.mozilla.org/ru/docs ...
- 各大浏览器CSS Hack收集
各大浏览器CSS Hack收集 >>>>>>>>>>>>>>>>>>>>> ...