#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的更多相关文章

  1. 动态切换tableView中的cell的种类

    动态切换tableView中的cell的种类 为什么要动态切换tableView中cell的种类呢?如果项目经理不出这种需求,你也就见不到这篇文章了:) 效果: 源码: 首先,你要准备3种cell,直 ...

  2. Swift - 设置tableView每个分区cell圆角

    1.// 重新绘制cell边框 func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRow ...

  3. iOS中关于动态Tableview中的cell数据传输的多线程问题解决之拙见

    iOS中关于动态Tableview中的cell数据传输的多线程问题解决之拙见 (2015-12-05 12:48:20)[编辑][删除] 转载▼     首先我们先明确一下问题: 1.因为UI是在主线 ...

  4. 更新tableView的某个cell

    更新tableView的某个cell 异步加载完数据后更新某个cell,这应该是非常常见的使用方法了,我们经常会用reloadData. 效果: 源码: // // RootViewControlle ...

  5. 优化tableView加载cell与model的过程

    优化tableView加载cell与model的过程 效果图 说明 1. 用多态的特性来优化tableView加载cell与model的过程 2. swift写起来果然要比Objective-C简洁了 ...

  6. 使用HVTableView动态展开tableView中的cell

    使用HVTableView动态展开tableView中的cell 效果: 源码: HVTableView.h 与 HVTableView.m // // HVTableView.h // HRVTab ...

  7. ios中自定义tableView,CollectionView的cell什么时候用nib加载,什么时候用标识重用

    做了一段时间的iOS,在菜鸟的路上还有很长的路要走,把遇到的问题记下来,好记性不如烂笔头. 在项目开发中大家经常会用到tableView和collectionView两个控件,然而在cell的自定义上 ...

  8. iOS中UITableView数据源刷新了,但tableview当中的cell没有刷新

    你会不会遇到通过断点查看数据源模型的确刷新了,但是tableview没有刷新的情况,我遇到了,并通过下面的方法解决了,供大家参考! 在tableview中的数据源代理方法 p.p1 { margin: ...

  9. 在tableView中设置cell的图片和文字

    // 设置UITableViewCellEditingStyle的 accessoryType UITableViewCellAccessoryNone,                   // d ...

随机推荐

  1. 如何将下载好的jar包添加到maven本地仓库

    1.首先在pom.xml中添加 <dependency>    <groupId>org.springframework.security</groupId>    ...

  2. ios socket通讯注意事项

    前段时间,在做objetive-c下的Sokcet通讯,当使用C++程序做服务端时,一切正常;当用JAVA做服务端时,双方收不到数据,在查阅了一些资料后,整理一下注意点 1 消息末尾加回车和换行符 o ...

  3. hibernate一对多关系映射(自身关联)

    示例:一个类别(Category)下面有多个子类别,多个子类别属于同一个父类别. public class Category  { private Integer id; private String ...

  4. 400. Nth Digit

    这个EASY难度的题怎么感觉比H的还难,昨天没做出来,今天才做出来.. 呃啊..我生 气 啦.. 直接看的答案,耻辱. 1 digit: 1~9 总共1×9个 2 digits: 10~99 总共2× ...

  5. 趣解curl

    Curl是Linux下一个很强大的http命令行工具,其功能十分强大. 1) 二话不说,先从这里开始吧! $ curl http://www.linuxidc.com 回车之后,www.linuxid ...

  6. HTML5简易在线画图工具

    继上次学习了HTML5的路径画圆做了动态时钟.异次元空间的反转做了运动的太阳系,这两天将画线.画圆.填充等知识点结合起来做了一个简易的在线画图工具: 查看DEMO:HTML5简易在线画图工具 功能包括 ...

  7. x264 编码器选项分析 (x264 Codec Strong and Weak Points) 1

    文章文件夹: x264 编码器选项分析 (x264 Codec Strong and Weak Points) 1 x264 编码器选项分析 (x264 Codec Strong and Weak P ...

  8. js控件位置

    function ShowSettingDiv() { var div = document.getElementById('ShowDiv'); //将要弹出的层 div.style.display ...

  9. Qt 学习之路:QStringListModel

    上一章我们已经了解到有关 list.table 和 tree 三个最常用的视图类的便捷类的使用.前面也提到过,由于这些类仅仅是提供方便,功能.实现自然不如真正的 model/view 强大.从本章起, ...

  10. 开始android博客分享

    现在开始写博客,分享android开发中的心得.