UI3_UITableView
//
// 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的更多相关文章
随机推荐
- 大礼包!ANDROID内存优化(大汇总)
写在最前: 本文的思路主要借鉴了2014年AnDevCon开发者大会的一个演讲PPT,加上把网上搜集的各种内存零散知识点进行汇总.挑选.简化后整理而成. 所以我将本文定义为一个工具类的文章,如果你在A ...
- oracle db打one-off-patch 一例
由于EBS form界面有一个报错,是一个小bug,以下打一个小patch修补一下. [以下的过程没有停库] 解压p8496830_111070_Linux-x86-64.zip cd 8496830 ...
- python中的reduce(转)
python中的reduce内建函数是一个二元操作函数,他用来将一个数据集合(链表,元组等)中的所有数据进行下列操作:用传给reduce中的函数 func()(必须是一个二元操作函数)先对集合中的第1 ...
- mysql主从复制详解
http://blog.csdn.net/hguisu/article/details/7325124
- errno多线程安全(转载)
一.errno的由来 在C编程中,errno是个不可缺少的变量,特别是在网络编程中.如果你没有用过errno,那只能说明你的程序不够健壮.当然,如果你是WIN32平台的GetLastError ...
- 20条IPTables防火墙规则用法!
导读 管理网络流量是系统管理员必需处理的最棘手工作之一,我们必需规定连接系统的用户满足防火墙的传入和传出要求,以最大限度保证系统免受攻击.很多用户把 Linux 中的 IPTables 当成一个防火墙 ...
- Replace INTO与INSERT INTO的不同之处
Replace INTO和INSERT INTO的区别: REPLACE的运行与INSERT很相似.只有一点例外,假如表中的一个旧记录与一个用于PRIMARY KEY或一个UNIQUE索引的新记录具有 ...
- MTD NANDFLASH驱动相关知识介绍
转:http://blog.csdn.net/zhouzhuan2008/article/details/11053877 目录 MTD总概述 MTD数据结构 MTD相关层实现 MTD,Memory ...
- magic_quotes_gpc(魔术引号开关)
magic_quotes_gpc函数在php中的作用是判断解析用户提示的数据,如包括有:post.get.cookie过来的数据增加转义字符“\”,以确保这些数据不会引起程序,特别是数据库语句因为特殊 ...
- 3.4html学习笔记之表格
<table border=""style="border-collapse:collapse"> <caption>表格</ca ...