//
// AppDelegate.m
// UI3_UITableView
//
// Created by zhangxueming on 15/7/13.
// 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
// UI3_UITableView
//
// Created by zhangxueming on 15/7/13.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import <UIKit/UIKit.h> @interface ViewController : UIViewController <UITableViewDataSource,UITableViewDelegate> @end
//
// ViewController.m
// UI3_UITableView
//
// Created by zhangxueming on 15/7/13.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import "ViewController.h" @interface ViewController ()
{
UITableView *_tableView;
NSMutableArray *_dataList;
} @end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
//UITableView继承UIScrollView
//UITableViewStyleGrouped 分组
//UITableViewStylePlain 无风格
_tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
//tableView 模式横向不能滚动,只能竖向滚动,contentSize自动计算
_tableView.backgroundColor = [UIColor cyanColor];
[self.view addSubview:_tableView]; //创建数据源
_dataList = [NSMutableArray array];
for (int i='A'; i<='Z'; i++) {
NSMutableArray *nameArray = [NSMutableArray array];
NSInteger count = arc4random()%10+1;
for (int j=0; j<count; j++) {
NSString *name = [NSString stringWithFormat:@"%c%d-name", (char)i, j];
[nameArray addObject:name];
}
[_dataList addObject:nameArray];
}
self.automaticallyAdjustsScrollViewInsets = YES; _tableView.dataSource = self;
_tableView.delegate = self; } #pragma mark ---UITableViewDataSource--- //返回每个分区中的显示的行数
//有多少个分区, 该方法被调用多少次
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [[_dataList objectAtIndex:section] count];
} //重用机制 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
//设定cell的重用标识符
static NSString *cellID = @"cell";
//先从表单元格重用队列中取出重用标识符的对象,如果为空,则创建表单元格对象
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellID];
} NSArray *nameArray = [_dataList objectAtIndex:indexPath.section];
NSString *name = [nameArray objectAtIndex:indexPath.row];
cell.textLabel.text = name;
cell.detailTextLabel.text = @"副标题test";
//设置选中状态的风格
cell.selectionStyle = UITableViewCellSelectionStyleGray;
//设置右侧指示风格
//详情风格
cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
//设置左侧图片
cell.imageView.image = [UIImage imageNamed:@"friend_weixin@2x"];
return cell;
} //返回分区的个数 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return [_dataList count];
} //设置分区的头标题
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
return [NSString stringWithFormat:@"第%c行",(char)(section+'A')];
} //返回表单元格的高度,默认是44
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 60;
} //选中表单元格的时候调用该方法
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"该表单元格被选中 section = %li row = %li", indexPath.section, indexPath.row);
//设置表单元格为非选中状态,
//[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
//表单元格被取消时调用
- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"该表单元格被取消 section = %li row = %li", indexPath.section, indexPath.row);
} - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} @end

UI3_UITableView的更多相关文章

随机推荐

  1. Swift 自己主动引用计数机制ARC

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

  2. Codeforces Round #250 (Div. 2)——The Child and Set

    题目链接 题意: 给定goal和limit,求1-limit中的若干个数,每一个数最多出现一次,且这些数的lowbit()值之和等于goal,假设存在这种一些数,输出个数和每一个数:否则-1 分析: ...

  3. iOS开发——图层OC篇&UIColor深入研究(CGColor,CIColor)

    UIColor深入研究(CGColor,CIColor) 由于跟人比较喜欢研究关于图层与动画方面的技术,正打算看看别人写的好东西,就遇到了好几个问题, 第一:UIClor类方法的使用 就是关于UICo ...

  4. 自增锁预分配ID

    http://www.cnblogs.com/xpchild/p/3825309.html mysql> show create table pp; CREATE TABLE `pp` ( `i ...

  5. php内核探索

    http://www.nowamagic.net/librarys/veda/special/PHP%E5%86%85%E6%A0%B8%E6%8E%A2%E7%B4%A2 关注PHP 源代码 Zen ...

  6. linux centos各种问题解决汇总

    1. Linux终端启动图形化程序界面时报错: No protocol specified问题: 这是因为Xserver默认情况下不允许别的用户的图形程序的图形显示在当前屏幕上. 如果需要别的用户的图 ...

  7. C++ 设计模式2 (面向对象设计原则)

    1. 变化是复用的天敌! 面向对象设计的最大优势在于 : 抵御变化 2. 重新认识面向对象 理解隔离变化: 从宏观层面来看,面向对象的构建方式更能适应软件的变化, 能将变化所带来的影响减为最小. 各司 ...

  8. [WinForm] VS2010发布、打包安装程序(超全超详细)

    1. 在vs2010 选择“新建项目”→“ 其他项目类型”→“ Visual Studio Installer→“安装项目”: 命名为:Setup1 . 这是在VS2010中将有三个文件夹, 1.“应 ...

  9. 实用技术——Eclipse 常用快捷键

    Eclipse的编辑功能非常强大,掌握了Eclipse快捷键功能,能够大大提高开发效率. 和编辑相关的快捷键 Eclipse中有如下一些和编辑相关的快捷键.  1. [ALT+/]  此快捷键为用户编 ...

  10. Java学习笔记——双等号和equals的区别

    一.==和equals的区别 1. ==可以用来比较基本类型和引用类型,判断内容和内存地址 2. equals只能用来比较引用类型,它只判断内容.该函数存在于老祖宗类 java.lang.Object ...