美文网首页
UItableview详解

UItableview详解

作者: 流水点点 | 来源:发表于2016-03-17 08:47 被阅读126次

UItableview 详解

详细介绍

* UITableView及其两种风格三部分

* UITableViewController

* UITableViewCell及其四种风格

*通过代理给UITableView设置cell

*性能优化

*通过代理增加删除cell



UITableView有两种风格:

*1、UITableViewStylePlain普通风格

*2、UITableViewStyleGrouped分组风格

三部分:

1.给tableView设置表头

tableView.tableHeaderView= [selfaddHeaderView];

//挂上代理

tableView.delegate=self;

tableView.dataSource=self;

2.给tableView设置表尾

tableView.tableFooterView= [selfaddFooterView];

UITableViewController就是一个自带UITableView的控制器

3.设置表头的方法

- (UIView*)addHeaderView{

UILabel*label = [[UILabelalloc]initWithFrame:CGRectMake(0,0,0,40)];

label.text=@"表头";

return label;

}

4.设置表尾的方法

- (UIView*)addFooterView{

UILabel*label = [[UILabelalloc]initWithFrame:CGRectMake(0,0,0,40)];

label.text=@"表尾";

return label;

}

- (void)addTableViewCell{

//右边出现小箭头

tabViewCell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;

//圈i加箭头

tabViewCell.accessoryType=UITableViewCellAccessoryDetailDisclosureButton;

//对号

tabViewCell.accessoryType=UITableViewCellAccessoryCheckmark;

//圈i

tabViewCell.accessoryType=UITableViewCellAccessoryDetailButton;

}

#pragma mark -通过代理给UITableView-设置cell

两种崩溃调试的方法

1、通过栈台找reason;

2、设置全局断点定位导致崩溃的代码

//返回tabview有多少行

- (NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section

{

return8;

}

- (NSInteger)numberOfSectionsInTableView:(UITableView*)tableView

{

return3;

}

//指定cell每次在屏幕上显示一个cell该方法就会调用一次

- (UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath

{

//UITableViewCell重用机制

// UITableView每次滑动,必定有消失的cell,系统会自动将这些消失的cell放到缓存池里,需要新cell时,系统先在缓存池里看是否有cell,有的话就利用,没有的话就新建。

/*前提:UITableView滑动

1、久的cell消失系统自动将这个cell放到缓存池里面

2、新的cell要显示,就会调用代理的方法。

1)首先看缓存池里面有么有cell

2)如果有cell就利用话没有的话就新建

3)在代理方法中返回设置的cell

*/

staticNSString*cellId =@"cellID";

//UITableViewCell *cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cellId"];

UITableViewCell*cell = [tableViewdequeueReusableCellWithIdentifier:cellId];

if(cell==nil) {

cell =[[UITableViewCellalloc]initWithStyle:UITableViewCellStyleSubtitlereuseIdentifier:cellId];

}

//cell.textLabel.text = @"二货";

//cell.textLabel.textColor = [UIColor lightGrayColor];

//cell.detailTextLabel.text = @"二货就是二货";

//UIImage *image = [UIImage imageNamed:@"20.tiff"];

//cell.imageView.image = image;

//static NSString *cellId = @"cellID";

//UITableViewCell *cell= [tableView dequeueReusableCellWithIdentifier:@""];

returncell;}

- (CGFloat)tabview:(UITableView*)tableView heightForRowAtindexPath:(NSInteger*)indexPath

{return100;}

#pragma mark---必须实现的两个代理方法-------------

//一组有多少行

- (NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section{}

//每行中的cell的实现

- (UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath{}

相关文章

  • IOS学习(15)-UITableView

    iOS开发系列--UITableView全面解析UITableViewCell详解UITableView属性及方法...

  • iOS 实战笔记3-(GeekBand)

    IOS TableView 详解 一、建立 UITableView DataTable = [[UITableVi...

  • UItableview详解

    UItableview详解 详细介绍 * UITableView及其两种风格和三部分 * UITableViewC...

  • UITableView编辑模式详解

    转载:UITableView 编辑模式详解作者:秋刀生鱼片 UITableView的相关编辑操作非常全,今天我们来...

  • UITableViewCell的复用机制

    **若对UITableViewCell不是很了解 **UITableView详解http://www.jiansh...

  • UITableView 编辑模式详解

    UITableView 编辑模式详解 UITableView的相关编辑操作非常全,今天我们来做一个总结。跟编辑相关...

  • iOS-UITableView 详解(一)

    iOS-UITableView 详解 (一) ✨建议收藏,用到时候一查就明白了UITableView可以说是iOS...

  • UITableView 详解

    UITableView 是 iOS 开发中必不可少的一个控件,基本上每一个项目都会有多个地方会用到。详细的了解UI...

  • UITableView 详解

    一、UITableView属性和方法 1、基础 2、数据刷新 3、信息Info 4、行的插入/删除/刷新 5、编辑...

  • UITableView详解

    -、建立 UITableView DataTable = [[UITableView alloc] initWit...

网友评论

      本文标题:UItableview详解

      本文链接:https://www.haomeiwen.com/subject/jmgqlttx.html