uitableviewcontroller使用

最近学习了uitableviewcontroller控制器以及uitableview使用。今天就来总结下。
-uitableview基本使用
首先来分析下uitableview:iOS中的tableview是可以分区的,每个区对应的行数;思考每一行显示的内容;用户选择一行所触发的事件。以上几个因素所设计到

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView//tableview 分区
 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section //对应区指定的行数
 - - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath//在此方法中实现cell、内容填充。

另注:NSIndexPath中已经包含对应的uitableviewcell(uitableview的子控件)的section和row。
-uitableviewcell style
[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@”cell”];中需要知道uitableviewcell的style,cell共有4个style:
-UITableViewCellStyleDefault:
UITableViewStylePlain style
-UITableViewCellStyleSubtitle:
-UITableViewCellStyleValue1:
-UITableViewCellStyleValue2:
以上4个style大家可以多试试,便知道他们的区别。
-分区
对于uitableview 分区之间留有间隔,直接在右边style选择grouped。
UITableViewStyleGrouped
- uitableviewcell的三个要素:
textlabel-uilable :cell上显示文字
detailtextlabel -uilabel:显示cell的详细内容
imageview-uiimageview用于显示cell上的图片信息。
-cell重用
uitableview界面中会有很多的cell,用过的cell并不会释放,而是放入了tableview的队列。因此在创建cell对象之前,先试着从队列中获取已存在的cell对象,if能拿到,则服用cell对象。
-刷新uitableview
[tableview reloadData]
-tableview 编辑模式
编辑模式即对uitableviewcell增、删、移动。
设置编辑模式 [self.tableView setEditing:boolean animated:YES];
-对cell编辑操作设置以及操作:

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath //对于可否编辑设置
- - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath //在此方法中实现增、删

--cell移动
对于cell的移动无非对数据的顺序进行改变:先删除此数据并在指定位置增加上此数据。

- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
- - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath 

-uitableviewcell中的accessoryview操作
默认情况下accessoryview是nil。通常情况下accessory view有4种style:UITableViewCellAccessoryNone,
UITableViewCellAccessoryDisclosureIndicator,
UITableViewCellAccessoryDetailDisclosureButton,
UITableViewCellAccessoryCheckmark。其中 UITableViewCellAccessoryDetailDisclosureButton是显示i,点击会触发:

(void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)

当然accessoryview也可以自己定义:即 cell.accessoryView=自定义view。
想到的就那么多,我自己写的uitablviewcontroller的使用代码下载地址:uitableview使用的demo下载
文中可能有很多的错误,望指正。谢谢。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值