//  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的更多相关文章

随机推荐

  1. Apache的Order Allow Deny心得

    Allow和Deny可以用于apache的conf文件或者.htaccess文件中(配合Directory, Location, Files等),用来控制目录和文件的访问授权. 所以,最常用的是: O ...

  2. php heredoc 与 nowdoc

    php heredoc 与 nowdoc heredoc 结构 heredoc 句法结构:<<<.在该运算符之后要提供一个标识符,然后换行.接下来是字符串本身,最后要用前面定义的标识 ...

  3. wp上一款应用的出生与死亡

    起因 因为自己买了个wp手机,所以对于微软的这个wp系统还是非常喜欢,无奈软件质量不高,过年前便买了个wp的开发者帐号,不是很贵,还想着为wp的生态系统做点贡献.无奈工作繁忙,一直没有机会去做.但是自 ...

  4. 关于ASP.NET中Button的OnClientClick属性

    Button有Click属性和OnClientClick属性,执行顺序上OnClientClick先执行,调用本地脚本,根据返回值确定是否执行Click. 当返回True则执行Click,当脚本错误或 ...

  5. 重新组织 vs 重新生成索引

    索引是数据库引擎中针对表(有时候也针对视图)建立的特别数据结构,用来帮助查找和整理数据.索引的重要性体现在能够使数据库引擎快速返回查询 结果.当对索引所在的基础数据表进行修改时(包括插入.删除和更新等 ...

  6. 一款基于jQuery仿淘宝红色分类导航

    今天给大家分享一款基于jQuery仿淘宝红色分类导航.这款分类导航适用浏览器:IE8.360.FireFox.Chrome.Safari.Opera.傲游.搜狗.世界之窗.效果图如下: 在线预览    ...

  7. jquery 动态事件绑定(0512)

    jquery动态事件绑定,父元素需为静态元素,(不能是动态生成): $("#parent").on("click","#child",fun ...

  8. NET开发必备工具之-LINQPad

    第一步,下载:http://www.linqpad.net/ 第二步,安装 第三步,打开LINQPad 第四步,添加链接 第五步,输入SQL Server,用户名,密码 第六步,点击OK,成功链接 第 ...

  9. kafka删除topic

    手动: 删除kafka存储目录(server.properties文件log.dirs配置,默认为"/tmp/kafka-logs")相关topic目录 删除zookeeper & ...

  10. Traveling by Stagecoach 状态压缩裸题

    Traveling by Stagecoach dp[s][v]  从源点到达  v,状态为s,v的最小值.  for循环枚举就行了. #include <iostream> #inclu ...