//
// AppDelegate.m
// UI4_UITableViewEdit
//
// 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
// UI4_UITableViewEdit
//
// 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
// UI4_UITableViewEdit
//
// 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.
_tableView = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStylePlain];
[self.view addSubview:_tableView]; //创建数据源
_dataList = [NSMutableArray array]; NSMutableArray *boys = [NSMutableArray array];
for (int i=0; i<10; i++) {
NSString *name = [NSString stringWithFormat:@"boy%d", i];
[boys addObject:name];
}
[_dataList addObject:boys]; NSMutableArray *grils = [NSMutableArray array];
for (int i=0; i<15; i++) {
NSString *name = [NSString stringWithFormat:@"gril%d", i];
[grils addObject:name];
}
[_dataList addObject:grils]; _tableView.delegate = self;
_tableView.dataSource = self; //编辑状态
self.navigationItem.leftBarButtonItem = self.editButtonItem;
} //设置表示图到编辑状态 - (void)setEditing:(BOOL)editing animated:(BOOL)animated
{
[super setEditing:editing animated:animated];
//让tableView处在编辑状态
[_tableView setEditing:editing animated:YES];
} #pragma mark ---UITableViewDataSource---
//返回分区的行数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [[_dataList objectAtIndex:section] count];
} //返回分区的个数
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return _dataList.count;
} //创建UITableViewCell - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *reuseIdentifier = @"cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:reuseIdentifier];
}
NSArray *array = [_dataList objectAtIndex:indexPath.section];
cell.textLabel.text = [array objectAtIndex:indexPath.row];
cell.detailTextLabel.text = [NSString stringWithFormat:@"age:%d",arc4random()%40+10];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.selectionStyle = UITableViewCellSelectionStyleGray;
return cell;
} - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
if (section==0) {
return @"男孩";
}
return @"女孩";
} - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} @end

UI4_UITableViewEdit的更多相关文章

随机推荐

  1. FullScreenDownloader

    https://github.com/Gitdefllo/FullScreenDownloader

  2. 如何理解js

    1.js/dom功能 2.performance 3.code organization 4.tools and flow 如何理解js代码,代码即业务. 如何快速理解代码业务.

  3. java.net.SocketException四大异常解决方案【转】

    java.net.SocketException如何才能更好的使用呢?这个就需要我们先要了解有关这个语言的相关问题.希望大家有所帮助.那么我们就来看看有关java.net.SocketExceptio ...

  4. oracle的触发器

    oracle的触发器分为语句级和行级两种类型,在视图上所创建的触发器叫做什么类型的触发器? DML触发器有三类: 1, insert触发器: 2, update触发器: 3, delete触发器: 触 ...

  5. Mysql之EXPLAIN显示using filesort

    索引使用经验: 1. 一条 SQL 语句只能使用 1 个索引 (5.0-),MySQL 根据表的状态,选择一个它认为最好的索引用于优化查询 2. 联合索引,只能按从左到右的顺序依次使用 Using w ...

  6. phpstorm一个窗口打开多个项目

    phpstorm默认一个窗口只显示一个项目,入股拟新建一个项目,他会给你个选项卡,问你是在新窗口打开新项目还是在本窗口打开. 能不能在一个窗口打开多个项目呢?就像sublime text那样,其实是可 ...

  7. storm 分组

    Stream Groupings: Stream Grouping定义了一个流在Bolt任务间该如何被切分.这里有Storm提供的6个Stream Grouping类型: 1. 随机分组(Shuffl ...

  8. 测试 IE 浏览器兼容性 VirtualBox + modern.ie

    VirtualBox 是开源的虚拟机软件,常用的虚拟机软件还有 VMware / Hyper-V / Paralles Desktop . modern.ie 是微软官方提供的用于测试网页在各版本 I ...

  9. java 解析XML文档

    Java 解析XML文档 一.解析XML文档方式: 1.DOM方式:将整个XML文档读取到内存中,按照XML文件的树状结构图进行解析. 2.SAX方式:基于事件的解析,只需要加载XML中的部分数据,优 ...

  10. React Native学习-CameraRoll

    react-native中CameraRoll模块提供了访问本地相册的功能. 在react版本为0.23.0的项目中,不支持Android,而且在iOS中使用CameraRoll还需要我们手动操作: ...