多个TableView

多个TableView

分类:            笔记2014-10-09 21:460人阅读评论(0)收藏编辑删除

uitableview

由于tableview需要有datasource和delegate,因此,你在程序里写的时候,如果多个tableview则用同一个方法使用。因此,去判定的话,需要这样去分辨

  1. #pragma mark -UITableViewDataSource
  2. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  3. if (tableView == recircleView){
  4. //如果当前的表是回收的
  5. return [list_recircle count];
  6. }
  7. if (tableView == useView){
  8. //如果当前的表是使用的
  9. return [list_use count];
  10. }
  11. return 0;
  12. }
  13. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  14. static NSString *UseTerminalCell = @"UseTerminalCell";
  15. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:UseTerminalCell];
  16. if (cell == nil) {
  17. cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:UseTerminalCell];
  18. }
  19. if (tableView == recircleView) {
  20. if(list_recircle != nil && [list_recircle count]>0){
  21. cell.textLabel.text =[ list_recircle objectAtIndex: [indexPath row] ];//写单元格的值
  22. }
  23. }else if (tableView == useView) {
  24. cell.textLabel.text =[ list_use objectAtIndex: [indexPath row] ];//写单元格的值
  25. }
  26. cell.textLabel.font = [UIFont systemFontOfSize:13];//设置字体
  27. return cell;
  28. }
时间: 2024-12-15 02:10:35

多个TableView的相关文章

TableView的accessoryButtonTappedForRow方法执行的时机

敲代码时遇到了这个问题,别偷懒,写下来备查. 当你在IB中对TableView中的accessory(注意,我说的是cell中的accessory,而不是cell)创建segue时,如果你在VC中同时实现以下3个方法,请问调用的次序是神马!? //1 func tableView(_ tableView: UITableView, accessoryButtonTappedForRowWith indexPath: IndexPath) //2 override func shouldPerfo

IOS TableView详解

一.建立 UITableView DataTable = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 320, 420)]; [DataTable setDelegate:self]; [DataTable setDataSource:self]; [self.view addSubview:DataTable]; [DataTable release]; 二.UITableView各Method说明 //Section总数 - (NS

设置tableview的滚动范围--iOS开发系列---项目中成长的知识三

设置tableview的滚动范围 有时候tableview的footerview上的内容需要向上拖动界面一定距离才能够看见, 项目中因为我需要在footerviw上添加一个按钮,而这个按钮又因为这个原因点不中,所以找到了解决办法! 添加如下方法即可 -(void)scrollViewDidScroll:(UIScrollView *)scrollView { self.tableView.contentSize = CGSizeMake(0,MZT_SCREEN_HEIGHT); }

tableView cell性能优化

通过一个标识表去缓冲池中寻找可循环利用的cell 如果缓存池找不到可循环利用的cell,创建一个新的cell,给cell贴个标识 给cell设置新的数据 代码如下cellForRowAtIndexPath方法中 //dequeue查找队列 //cell标识,static修饰局部变量:可以保证局部变量只分配一次存储空间 static NSString *ID = @"A"; UITableViewCell *cell = [tableView dequeueReusableCellWit

IOS学习笔记(三)TableVIew

如果有需要跟踪NSArray中的内容,需要重写descriptionWithLocal 方法.首先新建一个NSArray 的Category,在新建出来的.m文件中加入下列代码 - (NSString *)descriptionWithLocal:(id)local { NSMutableString *string = [NSMutableString string]; [string appendString:@"("]; for (id obj in self) { [strin

IOS7 TableView适配

ios7下的app都是全屏的,意思就是所有控制器的view默认都是从屏幕的(0,0)开始. 为了达到全屏效果的app,官方为UIviewController增加了几个属性: 1 @property(nonatomic,assign) UIRectEdge edgesForExtendedLayout NS_AVAILABLE_IOS(7_0); // Defaults to UIRectEdgeAll 2 @property(nonatomic,assign) BOOL extendedLayo

TableView 的那些坑

1. 分割线填满cell宽度, 并且设置分割线的颜色 1.1 利用系统的分割线填充 1.1.1 tableView 设置如下属性 // 给tableView设置如下属性值 tableView.layoutMargins = UIEdgeInsets.zero tableView.separatorInset = UIEdgeInsets.zero 1.1.2 设置完tableView属性你发现执行完可能好一点不过还需要设置cell的一个属性, 并且这个属性一定要在cell 即将显示的时候设置 f

tableView计算动态行高的总结

研究tableView怎么计算动态行高研究了两天一直还不太会,今天最终做出来了想要的效果. 首先.我在网上搜集了非常多资料,各种大神的总结,然后開始看.研究.试验,基本思路都是一样的. 1.一定要将label的numberOfLine设为0 2.获得文字信息所须要的size 3.将label的height设为titleSize.height 4.在- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIn

IOS xib在tableview上的简单应用(通过xib自定义cell)

UITableView是一种常用的UI控件,在实际开发中,由于原生api的局限,自定义UITableViewCell十分重要,自定义cell可以通过代码,也可以通过xib. 这篇随笔介绍的是通过xib自定义cell. 首先通过gif介绍如何创建xib. 然后实现代码部分,要注意的是实现代码的同时要使代码与xib相关联.-如图 下面便是代码,一些解释我在代码中注释了. ViewController.m // // ViewController.m // CX-Xib在tableView中的简单应用

iOS开发-UI (八)TableView

知识点: 1.UITableView使用 2.UITableView分段功能 3.UITableViewCell重用机制 ======================= UITableView使用 1.UITableView作用 2.UITableView创建 - (id)initWithFrame:(CGRect)frame style:(UITableViewStyle)style; UITableViewStyle: UITableViewStylePlain       列表模式 UIT