tableview中的delegate、DataSource原理
2017-11-14 10:35
579 查看
// // ViewController.m // #import "ViewController.h" @interface ViewController ()<UITableViewDelegate,UITableViewDataSource> // 4.遵守代理 @end @implementation ViewController - (void)viewDidLoad { UITableView * tabview = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain]; // 5.赋值代理 tabview.delegate = self; tabview.dataSource = self; [self.view addSubview:tabview]; } // 6.实现协议中的方法 -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return 5; } -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ static NSString * identifier = @"reuseId"; UITableViewCell * myCell = [tableView dequeueReusableCellWithIdentifier:identifier]; if (myCell == nil) { myCell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier]; } myCell.textLabel.text = @"test"; return myCell; } @end
相关文章推荐
- iOS tableview的delegate和datasource执行顺序
- Swift_TableView(delegate,dataSource,prefetchDataSource 详解)
- 打造轻量级ViewController之用Block分离TableView的dataSource
- 【iOS】UITableView delegate/dataSource方法执行顺序
- 0819-TableView(tableVeiw控件的代理)(tableView单组 lol数据展示)(tableView-汽车品牌logo 右侧a-z)(KVC)(tableView - 添加删除按钮出现)(自定义代理delegate)(内存)
- 分离 UITableView 的 Delegate 和 Datasource
- tableView下拉刷新和上拉加载的原理
- Ios 自定义表示图出现的相关问题UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:'
- UITableView的数据源(dataSource)和代理(delegate)
- UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath
- 【iOS7开发笔记】tableview之使用delegate的步骤
- UITableView和UIPickerView的Delegate和DataSource
- tableView重用cell原理
- 【iOS7开发笔记】tableview之Cell的重用原理
- 分离tableview的datasource , 实现ViewController “瘦身”
- UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath
- qt利用委托:QStyledItemDelegate,实现tableview 的表格项的自定义显示,如插入图片,绘制控件
- 点击tableView后面的button,通过响应者链条原理实现
- 【我们都爱Paul Hegarty】斯坦福IOS8公开课个人笔记37 TableView Delegate
- UITableView / UITableViewDataSource / UITableViewDelegate