//
// 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. sscanf和sprintf是scanf和printf家族用法 (转)

    sscanf和sprintf是scanf和printf家族用法 sscanf和sprintf是scanf和printf家族的一对成员,用于处理和分析字符串非常强大得两个函数头文件 stdio.h原型i ...

  2. Android经常使用自己定义控件

    http://www.see-source.com/androidwidget/list.html

  3. Android 实现自动接听和挂断电话功能

    添加权限 <uses-permission android:name="android.permission.CALL_PHONE"/> <uses-permis ...

  4. Android Compatibility package 兼容性开发套件

    我们认为Android 3.0平板电脑操作系统在美国时间2011年2月22日的正式推出,对于Android手机应用程序开发者所象征的意涵是: 之前大家所开发过的Android手机应用,除了可以在And ...

  5. C++将username部分用*取代

    简要:非常多时候中奖用户并不希望让别人知道他的ID.程序中我们就将他们的账号部分设置为*号显示. 比如:王小二->王*二. asadjsahd->a*********d. 代码: #inc ...

  6. EF 预热

    由于EF第一次加载比较慢,所以要对EF进行一次初始化的加载,类似第一次打开网页很慢,但第二次打开都很快了的原理一样:第一次把所有静态的图片和JS缓存到本地了:当第二次打开的时候都不需要再去下载这些东西 ...

  7. 【PHP代码审计】 那些年我们一起挖掘SQL注入 - 5.全局防护Bypass之宽字节注入

    0x01 背景 首先我们了解下宽字节注入,宽字节注入源于程序员设置MySQL连接时错误配置为:set character_set_client=gbk,这样配置会引发编码转换从而导致的注入漏洞.具体原 ...

  8. 类型推导:函数模板与auto

    1.从函数模板谈起 函数模板的类型推导机制是在c++98时代就有的,auto的类型推导机制与其基本一致,所以先理解函数模板类型推导. 函数模板可以用如下代码框架表示: #template<typ ...

  9. 3.1html学习之列表

    一.含义: ul:unorder list ol:order list li:list item dl:definition list dt:definition term dd:definition ...

  10. Spring MVC学习笔记 01

    applicationcontext.xml的配置 <?xml version="1.0" encoding="UTF-8" ?> <bean ...