UITableView的基本使用一
2014-02-06 20:40
267 查看
UITableView继承自UIScrollView,所以内容过多的分屏操作,也不用开发者操心了,开发中很多数据展示都用到这个空间,比如类似九宫格菜单和系统设置,通讯录等等。
![](https://img-blog.csdn.net/20140206202703015?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvY29vbGp1bmU=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
总结:UITableView中的内容是通过UITableViewCell返回内容,而控件中经常配合使用的alertView很像easyui中的弹出框
#pragma mark - 数据源方法 返回分组 -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ return 2; } #pragma mark - 数据源方法 返回每组的行数 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ if (section==0) { return self.tencent.count; }else{ return self.ali.count; } } #pragma mark 返回每组内容 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ UITableViewCell *cell=[[UITableViewCellalloc]initWithStyle:UITableViewCellStyleSubtitlereuseIdentifier:nil]; NSString *city=nil; if (indexPath.section==0) { city=self.tencent[indexPath.row]; }else{ city=self.ali[indexPath.row]; } //设置主标题 cell.textLabel.text=city; //设置图标 cell.imageView.image=[UIImageimageNamed:@"001.png"]; //设置副标题 cell.detailTextLabel.text=@"副标题"; //设置右边的箭头样式 cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator; return cell; } #pragma mark添加title -(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{ if (section==0) { return @"腾讯"; }else{ return @"阿里巴巴"; } } //添加脚信息 -(NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section{ if (section==0) { return@"腾讯旗下产品系列"; }else{ return@"阿里旗下产品系列"; } } //UITableViewDelegate 设置每一行cell的高度 -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ return 80; } //显示索引 -(NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView{ return @[@"a",@"b",@"b",@"c",@"d"]; } //监听行 -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ //弹框让控制器充当代理 UIAlertView *alert=[[UIAlertViewalloc]initWithTitle:@"title"message:@"提示"delegate:selfcancelButtonTitle:@"取消"otherButtonTitles:@"确定",nil]; // alert.tag=indexPath.row; self.currentRow=indexPath.row; self.currentSection=indexPath.section; alert.alertViewStyle=UIAlertViewStylePlainTextInput; //根据组和列获取lalbel的值 NSString *text=nil; if(indexPath.section==0){ text=self.tencent[indexPath.row]; }else{ text=self.ali[indexPath.row]; } //设置文本框的值 [alerttextFieldAtIndex:0].text=text; //显示弹出框 [alertshow]; } //alert点击了某个按钮 -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{ if (buttonIndex==1) { //根据tag获取 //获取第一个文本框输入的值 NSString *text=[alertView textFieldAtIndex:0].text; if(self.currentSection==0){ self.tencent[self.currentRow]=text; }else{ self.ali[self.currentRow]=text; } //刷新所有行数据 //[self.dataView reloadData]; NSIndexPath *path=[NSIndexPathindexPathForRow:self.currentRowinSection:self.currentSection]; //带动画刷新指定行数据 [self.dataViewreloadRowsAtIndexPaths:@[path]withRowAnimation:UITableViewRowAnimationLeft]; } } |
numberOfSectionsInTableView | 数据源方法 返回分组来源于代理UITableViewDataSource |
numberOfRowsInSection | 返回每组的行数来源于代理UITableViewDataSource |
cellForRowAtIndexPath | 返回每个cell的内容来源于代理UITableViewDataSource |
titleForHeaderInSection | 设置分组头title来源于代理UITableViewDelegate |
titleForFooterInSection | 设置分组脚title来源于代理UITableViewDelegate |
heightForRowAtIndexPath | 设置每行的高度来源于代理UITableViewDelegate |
sectionIndexTitlesForTableView | 设置每行的高度来源于代理UITableViewDelegate |
didSelectRowAtIndexPath | 监听选中行来源于代理UITableViewDelegate |
相关文章推荐
- UITableView 基本使用方法总结
- UI基础第十四弹:UITableview控件基本使用
- UITableView的基本使用
- UITableView 的基本使用
- UITableView 基本使用方法总结
- UITableView 基本使用方法总结
- UITableView基本使用方法
- UITableView 基本使用方法总结
- iOS开发UI篇—UITableview控件基本使用
- iOS,UITableView详细介绍之基本使用(一)
- iOS开发UI篇—UITableview控件基本使用
- (转载) UITableView 系列一 :基本使用方法 (显示,删除,添加图片,添加样式等
- UITableView 基本使用方法总结
- UITableView 基本使用方法
- ios--UITableview的基本使用方法
- iOS UITableView的基本使用
- iOS开发中UITableview控件的基本使用及性能优化方法
- UITableView 基本使用方法总结
- UITableView 基本使用方法
- iOS UI-表格控制器(UITableView)-基本使用