ios中列表UITableView的使用
来源:互联网 发布:酒店市场数据分析 编辑:程序博客网 时间:2024/05/20 02:54
UITableView的使用流程
首先在代码中实现两个代理UITableViewDelegate,UITableViewDataSource。
@interface RootViewController ()<UITableViewDelegate,UITableViewDataSource>@end
然后创建UITableView类,并设置代理。
UITableView *table=[[UITableView alloc]initWithFrame:CGRectMake(0,0, 375, 667-64) style:UITableViewStylePlain]; [self.view addSubview:table]; table.delegate=self; table.dataSource=self; //添加表头 UIImageView *imageview=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 375, 100)]; imageview.image=[UIImage imageNamed:@"163631.jpg"]; table.tableHeaderView=imageview;
实现代理的方法。
//UITableView的代理方法-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ //创建静态标识符 static NSString *identife=@"cell"; //根据标识符从重用池中取cell UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:identife]; //如果没有取到就创建一个新的 if(cell ==nil){ cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:identife]; } //对cell进行赋值 cell.textLabel.text=@"姜帅杰"; cell.detailTextLabel.text=@"姜帅杰哈哈"; cell.imageView.image=[UIImage imageNamed:@"163631.jpg"]; cell.accessoryType=UITableViewCellAccessoryDetailButton; //当在第三行时 if(indexPath.row==3){ } return cell;}-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return 10;}//cell的高度-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ return 160;}
使用数组为UITableView填充内容
首先你需要创建一个数组,并为其填入内容。
NSArray *data; data=[NSArray arrayWithObjects:@"盖伦",@"剑圣",nil];
然后在每个cell中设置值。
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ //创建静态标识符 static NSString *identife=@"cell"; //根据标识符从重用池中取cell UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:identife]; //如果没有取到就创建一个新的 if(cell ==nil){ cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:identife]; } //对cell进行赋值 cell.textLabel.text=[data objectAtIndex:indexPath.row]; cell.detailTextLabel.text=@"牛逼"; cell.imageView.image=[UIImage imageNamed:@"163631.jpg"]; cell.accessoryType=UITableViewCellAccessoryDetailButton; return cell;}
最常用的就是使用对象数组,可以为每个cell赋值更多的内容。
控制分区的代理方法
//分区的个数-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ return 3;}//分区的高度-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{ return 40;}//分区的标题-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{ return @"分区";}
UICollectionView也是差不多的。
阅读全文
0 0
- ios中列表UITableView的使用
- IOS 中UITableView使用
- ios UItableview的使用
- iOS-------------UITableView的使用
- IOS中UITableView使用总结
- IOS中UITableView使用总结
- iOS中使用UITableView的实现向左拉实现删除
- iOS UITableView的使用大全
- iOS UITableView的使用大全
- iOS--UITableView的详细使用
- iOS之UITableView的使用
- 【iOS开发】UITableView的使用
- iOS UITableView的基本使用
- iOS -UITableView-FDTemplateLayoutCell 的使用
- iOS开发UI篇章使用UItableview完成一个简单的QQ好友列表(一)
- iOS开发UI篇—使用UItableview完成一个简单的QQ好友列表(一)
- iOS开发UI篇—使用UItableview完成一个简单的QQ好友列表(二)
- iOS开发UI篇—使用UItableview完成一个简单的QQ好友列表(一)
- Resize Window一款可以切换浏览器屏幕分辨率大小的浏览器插件
- web开发 注意点 技巧点
- kubernetes1.8发布跟踪
- 完美解决MyEclipse提示过期Your 30-day trial of MyEclipse has expired.
- spring+oauth 遇到的问题
- ios中列表UITableView的使用
- 【LeetCode】valid-parenthesis
- [Muduo网络库源码分析] (10) base/ThreadPoll_cc_h_线程池
- linux常用文件操作命令
- 智能版石头剪刀布——c++实现
- Webpack "Invalid Host Header"
- UITableView+FDTemplateLayoutCell xib demo 例子
- MVC5学习小记(4):自定义授权过滤器
- PMM部署遇到的坑