一,效果图。

二,工程图。

三,代码。

RootViewController.h

#import <UIKit/UIKit.h>

@interface RootViewController : UIViewController
<UITableViewDataSource,UITableViewDelegate>
{
UITableView *mTableView;
}
@end

RootViewController.m

#import "RootViewController.h"

@interface RootViewController ()

@end

@implementation RootViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
} - (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view. //初始化背景色
[self initBackgroundView]; }
#pragma -mark -funcions
-(void)initBackgroundView
{
mTableView=[[UITableView alloc] initWithFrame:CGRectMake(0, 40, 320, self.view.bounds.size.height)];
mTableView.dataSource=self;
mTableView.delegate=self;
[self.view addSubview:mTableView];
}
#pragma -mark -UITableViewDelegate
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 2;
} -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (section==0) {
return 5;
}else if (section==1){
return 10;
}
return 10;
} -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 40;
} -(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{ static NSString *name=@"nearShop"; UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:name]; if (cell==nil) {
cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:name];
} cell.selectionStyle=UITableViewCellSelectionStyleNone; if (indexPath.section==0) {
cell.textLabel.text=@"食品";
}else if (indexPath.section==1){
cell.textLabel.text=@"商圈";
} return cell;
}
-(UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView* customView =[[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 30.0)] ;
customView.backgroundColor=[UIColor redColor]; UILabel * headerLabel = [[UILabel alloc] initWithFrame:CGRectZero] ;
headerLabel.backgroundColor = [UIColor redColor];
headerLabel.textColor = [UIColor blackColor];
headerLabel.font = [UIFont boldSystemFontOfSize:15];
headerLabel.frame = CGRectMake(0.0, 0.0, 320.0, 30.0); if (section == 0) {
headerLabel.text=@"热门商区";
}else if (section == 1){
headerLabel.text = @"分类";
} [customView addSubview:headerLabel]; return customView;
}

【代码笔记】iOS-一个tableView,两个section的更多相关文章

  1. IOS 作业项目 TableView两个section中cell置顶功能实现

    点击cell会置顶,其他的下移

  2. 【代码笔记】iOS-推荐收听,左右两个tableView

    一,效果图. 二,工程图. 三,代码. RootViewController.h #import <UIKit/UIKit.h> @interface RootViewController ...

  3. 【代码笔记】iOS-UIScrollerView里有两个tableView

    一,效果图. 二,工程图. 三,代码. RootViewController.h #import <UIKit/UIKit.h> @interface RootViewController ...

  4. 【代码笔记】iOS-点击城市中的tableView跳转到旅游景点的tableView,下面会有“显示”更多。

    一,效果图. 二,工程图. 三,代码. RootViewController.h #import <UIKit/UIKit.h> @interface RootViewController ...

  5. IOS中TableView的使用(1) -创建一个简单的tableView

    创建一个简单的tableView: #import <UIKit/UIKit.h> /*tableView 一定要遵守这两个协议: UITableViewDataSource,UITabl ...

  6. 【代码笔记】iOS-scrollerView里多个tableView加搜索框

    一,效果图. 二,工程图. 三,代码. RootViewController.h #import <UIKit/UIKit.h> #import "customCell.h&qu ...

  7. 【代码笔记】iOS-3个section,每个都有header.

    一,效果图: 二,工程目录. 三,代码 RootViewController.h #import <UIKit/UIKit.h> @interface RootViewController ...

  8. 【代码笔记】iOS-点击顶点处,弹出另一个小的界面

    一,效果图. 二,文件目录. 三,代码. RootViewController.h #import <UIKit/UIKit.h> @interface RootViewControlle ...

  9. 【代码笔记】iOS-带索引的tableView

    一,效果图. 二,工程图. 三,代码. RootViewController.h #import <UIKit/UIKit.h> @interface RootViewController ...

随机推荐

  1. 微软收购Xamarin,你怎么看?

    今天的最大新闻就是微软收购热门初创企业Xamarin,从网上的反馈大部分都是积极的,也有担心微软在把Xamarin移动开发技术整合进VS的同时,还很有可能废掉MONO的GUI客户端能力只保留.net ...

  2. Entity Framework 6 Recipes 2nd Edition(9-6)译->管理断开时的并发

    9-6. 管理断开时的并发 问题 想要确保只接受在WCF客户端并发令牌未被修改的实体. 解决方案 我们有一个如Figure 9-6所示的模型. Figure 9-6订单实体模型 我们想通过WCF服务来 ...

  3. Java 8函数编程轻松入门(三)默认方法详解(default function)

    default出现的原因 Java 8中对API最大的改变在于集合类,Java在持续演进,但是它一直保持着向后兼容. 在Java 8中为Collection接口增加了stream方法,这意味着所有实现 ...

  4. redis成长之路——(五)

    单例.哨兵.Cluster redis应用广泛,主要体现于实际场景的可用化,但是对于码农来说初步入手很多理念难以理解:码农的想法就是:为什么我要管那么多,我只想用,能用就行!所以必须将三个场景透明化. ...

  5. backup3:master 数据库的备份和还原

    在SQL Server 中,master 数据库记录系统级别的元数据,例如,logon accounts, endpoints, linked servers, and system configur ...

  6. Redis数据结构详解之Zset(五)

    序言 Zset跟Set之间可以有并集运算,因为他们存储的数据字符串集合,不能有一样的成员出现在一个zset中,但是为什么有了set还要有zset呢?zset叫做有序集合,而set是无序的,zset怎么 ...

  7. 计算机程序的思维逻辑 (53) - 剖析Collections - 算法

    之前几节介绍了各种具体容器类和抽象容器类,上节我们提到,Java中有一个类Collections,提供了很多针对容器接口的通用功能,这些功能都是以静态方法的方式提供的. 都有哪些功能呢?大概可以分为两 ...

  8. 如何通过官方渠道为Windows 10 添加具有中国特色的字体

    Windows 10的变化细节上个人认为要比Windows 8多很多,而且很多功能找到之后还是小惊喜,就是挺多好用的地方居然都不正经宣传一下,微软真是搞得悄悄地干活? 今天为大家介绍一下通过官方途径添 ...

  9. 制作自己的MVC框架(一)——简单粗暴的实现

    现在市面上有很多成熟的MVC框架,可以拿来直接用,但自己造一下轮子其实也挺有意思的. 下面先来看个最简单粗暴的MVC实现. 5个文件就能实现最简单的MVC,在Apache中设置一个虚拟目录,配置个简单 ...

  10. jvm系列(一):java类的加载机制

    java类的加载机制 1.什么是类的加载 类的加载指的是将类的.class文件中的二进制数据读入到内存中,将其放在运行时数据区的方法区内,然后在堆区创建一个java.lang.Class对象,用来封装 ...