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>)
{
moment_status_bar=;
}
tableView_Inform=[[UITableView alloc]initWithFrame:CGRectMake(, +moment_status_bar, ,Phone_Height-- )];
[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 == ) { return 44.0;
} else {
return 44.0;
}
}
//一共有几组 返回有几个 section 块
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return ;
}
//每组有几行 返回 每个块 有几行cell
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return ;
}
- (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 UITableView Group&Section的更多相关文章

  1. iOS UITableView的Section Footer加入button

    郝萌主倾心贡献,尊重作者的劳动成果.请勿转载. 假设文章对您有所帮助,欢迎给作者捐赠.支持郝萌主,捐赠数额任意.重在心意^_^ 我要捐赠: 点击捐赠 Cocos2d-X源代码下载:点我传送 在处理UI ...

  2. IOS UITableView NSIndexPath属性讲解

    IOS UITableView NSIndexPath属性讲解   查看UITableView的帮助文档我们会注意到UITableView有两个Delegate分别为:dataSource和deleg ...

  3. 下拉刷新和UITableView的section headerView冲突的原因分析与解决方案

    UITableView:下拉刷新和上拉加载更多 [转载请注明出处] 本文将说明具有多个section的UITableView在使用下拉刷新机制时会遇到的问题及其解决方案. 工程地址在帖子最下方,只需要 ...

  4. iOS UITableView划动删除的实现

    标签:划动删除 iphone 滑动删除 ios UITableView 原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://rainb ...

  5. 快速设置UITableView不同section对应于不同种类的cell

    快速设置UITableView不同section对应于不同种类的cell 本文主要是为了写明如何在UITableView中,一个section对应于一种类型的cell,写起来不凌乱. 在不封装任何类的 ...

  6. iOS UITableView Tips(2)

    #TableView Tips(2) (本来想一章就结束TableView Tips,但是发现自己还是太天真了~too young,too simple) ##架构上的优化 在Tips(1)中指出了一 ...

  7. ios 更改UITableview group形式 两个section之间的距离

    -(CGFloat)tableView:(UITableView*)tableView heightForHeaderInSection:(NSInteger)section { return 1.0 ...

  8. IOS UItableView得到group如何摆脱的剪裁线条样式问题

    在他们的定义UItableView什么时候,选择当style至Group时间,后常透明切割线依然,去除.只有再次刷新了BackgroundView它可以覆盖原来的 //取消切割线 UIView *vi ...

  9. iOS UITableView中关于cell里的按钮被点击时如何确定是哪一个section

    在section=10:row=1:的UITableView中,每一个cell都带有一个按钮,例如如下的图片一样每一个cell中都有一个“进入店铺的按钮”,但是如果我点击相应的cell要进入对应的店铺 ...

随机推荐

  1. [转]undefined reference问题总结

    转自http://ticktick.blog.51cto.com/823160/431329 最近在Linux下编程发现一个诡异的现象,就是在链接一个静态库的时候总是报错,类似下面这样的错误: (.t ...

  2. ODBC 是什么

    In computing, ODBC (Open Database Connectivity) is a standard programming language middleware API fo ...

  3. How Tomcat Works(十一)

    本文接下来分析tomcat的类载入器,tomcat需要实现一个自定义的载入器,而不能使用系统类载入器 (1)限制serlvet访问当前运行的java虚拟机中环境变量CLASSPATH指明的路径下的所有 ...

  4. 操作Cookie的一个陷阱服务器端获取不了maxAge或其它属性

    搞了几天终于弄明白了这个问题: 在读取Cookie,然后操作时,除了getName(),getValue()外,不要妄图得到其他信息,如下方法不会得到值的:cookie.getMaxAge();=== ...

  5. android 自定义控件(初篇)

    android 自定义控件 在写UI当中很多时候会用到自定义的控件,其实自定义控件就像是定义一个类进行调用就OK了.有些相关的感念可以查看API 下面就用个简单的例子来说明自定义控件: public ...

  6. UI:这段时间的小总结

    关于 UITAbleView 的重用机制 参考1  参考2   参考3 关于 UITableViewController  的知识来自博客 参考1  参考2  参考3 总结 一个工程的基本框架的规范写 ...

  7. Web性能优化之图片优化

    http://get.jobdeer.com/6513.get 其中APNG和WebP格式出现的较晚,尚未被Web标准所采纳,只有在特定平台或浏览器环境可以预知的情况下加以采用,虽然均可以在不支持的环 ...

  8. 16.ARC

    Swift 使用自动引用计数(ARC)机制来跟踪和管理应用程序的内存.通常情况下,Swift 内存管理机制会一直起作用,我们无须自己来考虑内存的管理.ARC 会在类的实例不再被使用时,自动释放其占用的 ...

  9. 一条结合where、group、orderby的linq语法

    DataTable dt = (from x in dsResult.Tables[0].AsEnumerable() where DataTrans.CBoolean(x["IsCheck ...

  10. MON166 User's Guide

    MON166 is a debug monitor for C16x and ST10 user programs. It consists of: A configurable monitor pr ...