//
// 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. LintCode 子树

    easy 子树 19% 通过 有两个不同大小的二进制树: T1 有上百万的节点: T2 有好几百的节点.请设计一种算法.判定 T2 是否为 T1的子树. 您在真实的面试中是否遇到过这个题? Yes 例 ...

  2. 【JavsScript】Ember.js

    现在,我们经常都可以看到复杂的JavaScript应用程序,由于这些应用程序变得越来越复杂,一长串的jQuery回调语句或者通过应用程序在各个状态执行不同的函数调用,这些做法都会变得无法再让人接受,这 ...

  3. EasyUI基础入门之Pagination(分页)

    前言 对于一些企业级的应用来说(非站点),页面上最为基本的内容也就是表格和form了.对于类似于ERP这类系统来说数据记录比較大,前端表格展示的时候必需得实现分页功能了.恰巧EasyUI就提供了分页组 ...

  4. google对js延迟加载方案的建议

    浏览器在执行JavaScript代码时会停止处理页面,当页面中有很多JavaScript文件或代码要加载时,将导致严重的延迟.尽管可以使用defer.异步或将JavaScript代码放到页面底部来延迟 ...

  5. Spring Mvc返回html页面404错误解决记录--转载

    原文地址:http://53873039oycg.iteye.com/blog/2061992 以前使用Spring Mvc时候都是返回jsp页面或者ftl页面,昨天想返回html页面,spring- ...

  6. 如何编写自己的Linux安全检查脚本?

    因为本人工作中要涉及到很多东西,审计(日志.数据神马的).源代码审计.渗透测试.开发一大堆东西,有些东西,越是深入去做,越会发现,没有工具或脚本,工作起来是有多么的坑. 工作的这段时间,自己写了几个工 ...

  7. python 操作word文档

    因为工作需要操作一些word文档,记录一下学习思路 #-*- encoding: utf8 -*- import win32com from win32com.client import Dispat ...

  8. C. Anya and Smartphone

    C. Anya and Smartphone time limit per test 1 second memory limit per test 256 megabytes input standa ...

  9. IOS 给图片添加水印(文字)

    有时候上传图片要加唯一标识,简单的就是添加一个水印.这里水印我们讲文字,可以是当前系统时间.坐标.地理位置等 原理就是把一个字符串写到图片上,并且字(font)的大小由图片大小控制. 以下是封装好的一 ...

  10. [wordpress]wp-api-jwt-auth 尝试添加运行在多站点中 need change

    Hi,Thank you this plugin,because i use this plugin on Wordpress one Network,so the request other api ...