UIView 与 UITableView

 

UIView 

UIView 继承于 UIResponder类,UIView 用于实现视图。UIView类定义了视图的基本属性和方法  。

UIView 的类定义是一个显示在屏幕上的矩形区域,并在这方面管理内容的接口。

 

   initWithFrame:

   初始化并返回一个新的拥有特定大小的视图对象 

   UIView *v=[[UIView alloc] initWithFrame:CGRectMake(0,0,320,480)];

   backgroundColor:

   背景的颜色

   V.backgroundColor=[UIColor brownColor];

   addSubview:

   加一个视图到一个视图里面

   [self.View addSubview:v];

   [v1 addSubview:v2];

   bringSubviewToFront:

    将子视图移到前面

    sendSubviewToBack:

    将子视图推送到后面:

    removeFromSuperview:

     把子视图删除

    insertSubview:atIndex:

    在特定位置插入子视图

    intsertSubview:aboveSuview:

   插入子视图在某个视图之上

   intsertSubview:belowSubview:

    插入子视图在某个视图之下

    exchangeSubviewAtIndex:withSubviewAtIndex:

    交换两个子视图的位置

UITableView

UITableView 的一个表视图是一种手段,用于显示和编辑信息的分层列表。UITableView 继承自UIScrollView(滚动视图),有两种风格 UITableViewStylePlain(不分组显示)和UITableViewStyleGrouped(分组显示)。UITableView 有两个协议 UITableViewDelegate(委托协议) 和UITableViewDataSource(数据源协议)。

 

UITableViewDataSource 是提供显示在表格单元上用的数据。其中有三个必须实现的核心方法:

  -(NSInteger)numberofSectionInTableView:(UITableView*)tableView;

  获得表视图的块个数,默认返回1

 

 -(NSInteger)tableView:(UITableView*)tableViewnumberOfRowsInSection:(NSItneger)section;

   这个方法返回指定块中的行数,不同的块返回不同的行数可以用switch和case语句

 

 -(UITableViewCell*)tableView:(UITableView*)tableViewcellForRowAtIndexPath:(NSIndexPath*)index;

 这个方法返回某一行的数据(表单元)NSIndexPath是块的编号(section)和行号(row)的组合。通过NSIndexPath

 就可以确定表单元(Table cell)位置。

 

UITableViewDelegate主要是提供一些可选的方法,用来控制tableview的选择  、指定section 的头和尾的显示以及协助完成cell的删除和排序的功能。一些委托方法:

 

 -(NSArray*)sectionIndexTitlesForTableView:(UITableView*)tableView;

设置Section的数量

 

 -(NSSTring*)tableView:(UITableView*)tableViewtitleForHeaderInSection:(NSInteger)setion;

设置每个section显示的Title

 

 -(NSInteger)tableView:(UITableView*)tableViewindentationLevelForRowAtIndexPath: (NSIndexPath*)indexPath;

设置让UITableView行缩进

 

NSIndexPath *de=[NSIndexPath indexPathForRow:row inSection:section];

[TopicsTable selectRowAtIndexPath:de animated:YES scrollPosition:UITableViewScrollPositionNone];

返回当前所选Cell

 

[tableView setSeparatorStyle:UITableViewCellSelectionStyleNone];设置 Table cell 有分割线

[tableView setBackgroundColor:UIColor clearColor] 设置UITableView背景为透明

 

-(void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath

设置选中Cell的响应事件

 

[tableView deselectRowAtIndexPath:indexPath animated:YES]; 选中后的反显颜色即刻消失

 

-(NSIndexPath*)tableView:(UITableView*)tableViewwillSelectRowAtIndexPath:(NSIndexPath*)indexPath;

设置选中的行所执行的动作

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值