IOS UITableView Group&Section
UItableView 根据数据结构不同 会有不同样式 关键在两个代理 tableviewdelegate&tabledatasourse
下面代码是我实施的Group 在模拟器中 ios6.1和ios7
并且滚动后相应的section会“置顶”,效果不错哦!
核心代码:
#import <UIKit/UIKit.h> @interface AnnouncementViewController : UIViewController<UITableViewDataSource,UITableViewDelegate> { UITableView *tableView_Inform; } @end ////////////////////////////////////////////////////// - (void)viewDidLoad { [self.view addSubview: [NavView NavView_Title:@"通告"]]; [super viewDidLoad]; [self TableView]; } -(void)TableView { if(StatusBar_System>0) { moment_status_bar=20; } tableView_Inform=[[UITableView alloc]initWithFrame:CGRectMake(0, 44+moment_status_bar, 320,Phone_Height-64-44 )]; [self.view addSubview:tableView_Inform]; tableView_Inform.dataSource=self; tableView_Inform.delegate=self; } /* ios7以前的group 一般是圆角的,ios7以后没有圆角 苹果鼓励并支持更大的阅读面积 所以我把ios6的圆角也去掉了 也挺帅的 不是么 */ //每一个section中间的宽度 可以根据需要设定 如果第一个section不需要宽度 就return 0; - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { if (!section == 0) { return 44.0; } else { return 44.0; } } //一共有几组 返回有几个 section 块 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 4; } //每组有几行 返回 每个块 有几行cell - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return 4; } - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { NSArray *array=[NSArray arrayWithObjects:@"One",@"Two", @"Three",@"Four",nil]; return [array objectAtIndex:section]; } //cell注意数据结构的变化 indexPath.row 是循环变化的
//这里cell 我是写死的 可以自定义哦哦
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *SimpleTableIdentifier = @"SimpleTableIdentifier"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: SimpleTableIdentifier]; if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier: SimpleTableIdentifier] ; } NSLog(@"%d",indexPath.row); return cell; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. }
附加 ios6和ios7的两个效果图
分类:
IOS UI
posted on 2014-06-18 16:33 ACM_Someone like you 阅读(682) 评论(0) 编辑 收藏 举报
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
· [.NET]调用本地 Deepseek 模型
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· .NET Core 托管堆内存泄露/CPU异常的常见思路
· PostgreSQL 和 SQL Server 在统计信息维护中的关键差异
· CSnakes vs Python.NET:高效嵌入与灵活互通的跨语言方案对比
· DeepSeek “源神”启动!「GitHub 热点速览」
· 我与微信审核的“相爱相杀”看个人小程序副业
· Plotly.NET 一个为 .NET 打造的强大开源交互式图表库
· 上周热点回顾(2.17-2.23)