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的更多相关文章
随机推荐
- 使用sqlite的命令操作
一: 首先进入到D:\java\android\android-sdk\platform-tools文件夹里面 二:使用adb shell进入shell命令方式行(注意要想进入shell里面的操作 ...
- 我的git使用记录
git的教程现在琳琅满目,需要学习的东西也有很多,一下子接受不了那么多的东西,所以打算记录在实用的过程中常用的操作和遇到的问题. 基本操作 git init git add . git add -A ...
- SQL注入原理解说,非常不错!
原文地址:http://www.cnblogs.com/rush/archive/2011/12/31/2309203.html 1.1.1 摘要 日前,国内最大的程序猿社区CSDN站点的用户数据库被 ...
- Golang学习 - unicode/utf8 包
------------------------------------------------------------ // 编码所需的基本数字 const ( RuneError = '\uFFF ...
- JavaScript随机数
function random(start,end){ var total=start+end; return Manth.floor(Manth.random()+total-start); }
- Python练习题 027:对10个数字进行排序
[Python练习题 027] 对10个数字进行排序 --------------------------------------------- 这题没什么好说的,用 str.split(' ') 获 ...
- Redis缓存、MemCached和.Net内部缓存的切换使用
接口文件:IDataCache.cs using System; using System.Collections.Generic; using System.Linq; using System.T ...
- 个人总结ANDROID开发事项
theme:none,Holo Dark(全黑),Holo Light(全白),Holo Light width Dark action Bar(全白,活动栏是黑) Create Activity: ...
- HDU 1088 Write a simple HTML Browser 有点恶心的字符串题
这题是从某个群里听别人在抱怨这题老是PE,打开status果然满眼的Presentation Error...于是闲着来做了一下. 其实挺水的,不过各种设定多一点,注意一点就行了. 一开始以为词数超过 ...
- 【原创】mac 上如何安装及切换输入法
1. 安装输入法 刚购入mac mini一台,默认只有英文输入法,而自己用习惯了sogou输入法,于是就在网上下载安装了一个sogou拼音输入 for mac. 下载完毕后,在屏幕下方的dock区域右 ...