UI4_UITableViewSectionIndex
// AppDelegate.m
// UI4_UITableViewSectionIndex
//
// Created by zhangxueming on 15/7/14.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import "AppDelegate.h"
#import "ViewController.h" @interface AppDelegate () @end @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
ViewController *root = [[ViewController alloc] init];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:root];
self.window.rootViewController = nav;
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible]; return YES;
}
//
// ViewController.h
// UI4_UITableViewSectionIndex
//
// Created by zhangxueming on 15/7/14.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import <UIKit/UIKit.h> @interface ViewController : UIViewController<UITableViewDataSource, UITableViewDelegate> @property (strong, nonatomic)UITableView *tableView;
@property (strong, nonatomic)NSMutableArray *dataList; @end //
// ViewController.m
// UI4_UITableViewSectionIndex
//
// Created by zhangxueming on 15/7/14.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import "ViewController.h" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[self creatUI];
[self creatDataSource];
} - (void)creatDataSource
{
_dataList = [NSMutableArray array];
for (int i='A'; i<='Z'; i++) {
NSInteger count = arc4random()%10+1;
NSMutableArray *array = [NSMutableArray array];
for (int j=0; j<count; j++) {
NSString *name = [NSString stringWithFormat:@"人物:%d", j+1];
[array addObject:name];
}
[self.dataList addObject:array];
}
} - (void)creatUI
{
_tableView = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStylePlain];
[self.view addSubview:self.tableView];
//设置代理
self.tableView.delegate = self;
self.tableView.dataSource = self;
self.automaticallyAdjustsScrollViewInsets = YES;
self.view.backgroundColor = [UIColor whiteColor];
} #pragma mark ---UITableViewDataSource--- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return self.dataList.count;
} - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [[self.dataList objectAtIndex:section] count];
} - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellId = @"cell";
UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:cellId];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellId];
}
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.textLabel.text = [[self.dataList objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];
return cell;
} - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
return [NSString stringWithFormat:@"第%c分区", (char)(section+'A')];
} //设置分区头标题的高度
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return 50;
} //创建分区标题数组
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
{
NSMutableArray *array = [NSMutableArray array];
[array addObject:UITableViewIndexSearch];
for (int i='A'; i<='Z'; i++) {
NSString *str = [NSString stringWithFormat:@"%c", (char)i];
[array addObject:str];
}
return array;
} //切换到指定的分区
- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index
{
return index-1;
} - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} @end
UI4_UITableViewSectionIndex的更多相关文章
随机推荐
- C++ Code_animateCtrl
Code:: 播放 if (!m_animate1.Open("C:\\copy.avi")) { MessageBox("NULL& ...
- Ubuntu下很给力的下载工具
Windows下的下载工具--迅雷,之所下面载速度快,乃是它能搜索资源.为己所用,而不是只从原始地址这单一资源处下载. Ubuntu下也有类似的工具,那就是aira2. aira2是一个命令行下载工具 ...
- 使用SurfaceView和MediaPlayer实现视频做为背景
场景:像我们在Uber应用开场,看到一一段视频作为開始.这样子让用户非常快投入应用使用的场景中去,这样的以视频作为开场的应用,我们是不是认为非常高大上呢,哈哈,事实上是使用了SerfaceView去载 ...
- vi 命令 使用方法
一.Unix编辑器概述 编辑器是使用计算机的重要工具之中的一个,在各种操作系统中,编辑器都是不可缺少的部件.Unix及其类似的ix 操作系统系列中,为方便各种用户在各个不同的环境中使用,提 ...
- png图片那点事
PNG图片格式现在包含三种类型: 1.PNG8 256色PNG的别名 2.PNG24 全色PNG的别名 3.PNG32 全色PNG的别名 基本上PNG32就是PNG24,但 ...
- oracle 有用站点
使用oradebug修改数据库scn – 提供专业ORACLE技术咨询和支持@Phone13429648788 - 惜分飞 Solaris上使用DTrace进行动态跟踪 老熊的三分地-Oracle及数 ...
- Data Structure 之 最优二叉树
给定n个权值作为n的叶子结点,构造一棵二叉树,若带权路径长度达到最小,称这样的二叉树为最优二叉树,也称为哈夫曼树(Huffman tree).哈夫曼树是带权路径长度最短的树,权值较大的结点离根较近. ...
- C. Ilya and Sticks
C. Ilya and Sticks time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- 【Android Studio使用教程4】Android Studio下载
鉴于Android官网上下载很慢,Android Studio等已在网盘分享:Android Studio 网盘下载路径: windows:http://yunpan.cn/cfTszP2wrJxdD ...
- 转: ffmpeg 的deom列表
http://blog.csdn.net/leixiaohua1020/article/details/47072861