UI4_UITableViewEdit
//
// 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的更多相关文章
随机推荐
- 次表面散射(SubSurface Scattering) Shader 【转】
原文 http://www.azure.com.cn/article.asp?id=231 用深度值近似模拟物体的厚度,厚度越小处透光越多. varying vec4 position;varying ...
- replace into
讨人喜欢的 MySQL replace into 用法(insert into 的增强版) 在向表中插入数据的时候,经常遇到这样的情况:1. 首先判断数据是否存在: 2. 如果不存在,则插入:3.如果 ...
- hdu5071 2014 Asia AnShan Regional Contest B Chat
模拟题: add的时候出现过的则不再添加 close的时候会影响到top rotate(Prior.Choose)的时候会影响到top /*============================== ...
- TP复习3
## ThinkPHP 3.1.2 CURD特性#讲师:赵桐正微博:http://weibo.com/zhaotongzheng 本节课大纲: 一.ThinkPHP 3 的CURD介绍 (了解) 二. ...
- PHP函数spl_autoload_register()用法和__autoload()介绍(转)
详细出处参考:http://www.jb51.net/article/29624.htm 又是框架冲突导致__autoload()失效,用spl_autoload_register()重构一下,问题解 ...
- install root certificate failed, Please run as administrator/root/sudo
在钥匙窜中导入 证书就可以了
- [vba]excel中求选中数据和为给定数所有的组合
昨天下午开始学习的vba,累死了,肯定有bug,待调试 vba程序如下: Dim aSum As Integer Dim tSum As Integer ) As Integer Dim arrMax ...
- Web前段优化,提高加载速度 css
前言: 在同样的网络环境下,两个同样能满足你的需求的网站,一个"Duang"的一下就加载出来了,一个纠结了半天才出来,你会选择哪个?研究表明:用户最满意的打开网页时间是2-5秒, ...
- QQ会员AMS平台PHP7升级实践
作者:徐汉彬链接:https://zhuanlan.zhihu.com/p/21493018来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出处. QQ会员活动运营平台(AMS ...
- L - Abbott's Revenge(比较复杂的bfs)
Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submit Status Practice UV ...