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的更多相关文章
随机推荐
- poj - 2774 - Long Long Message
题意:输入2个长度不超过100000的字符串,问它们最长公共子串的长度. 题目链接:http://poj.org/problem?id=2774 ——>>后缀数组!后缀数组!-从LJ的&l ...
- [Angular2 Form] Display Validation and Error Messaging in Angular 2
Angular 2’s ngModel provides error objects for each of the built-in input validators. You can access ...
- Quartz中Cron表达式使用方法
Quartz中CronTrigger支持日历相关的反复时间间隔(比方每月第一个周一运行),而不是简单的周期时间间隔. 它的调度规则基于 Cron 表达式. 以下就来说一下Cron表达式的规则及使用方法 ...
- iOS开发——实战OC篇&环境搭建之Xib(玩转UINavigationController与UITabBarController)
iOS开发——实战OC篇&环境搭建之Xib(玩转UINavigationController与UITabBarController) 前面我们介绍了StoryBoard这个新技术,和纯技术 ...
- 给学习IT、编程者的看
Preface: 我始终认为,对一个初学者来说,IT界的技术风潮...... Content: 我始终认为,对一个初学者来说,IT界的技术风潮是不可以追赶的,而且也没有能力去追赶.我时常看见自己的DD ...
- LeetCode30 Substring with Concatenation of All Words
题目: You are given a string, s, and a list of words, words, that are all of the same length. Find all ...
- 小白日记51:kali渗透测试之Web渗透-WebShell(中国菜刀、WeBaCoo、Weevely)
webshell 本质:<?php echo shell_exec($_GET['cmd']);?> windows平台 中国菜刀官网:胖客户端程序,国产中比较优秀的webshell,适用 ...
- java操作spark1.2.0
虽然推荐的是scala,但是还是试一下 package org.admln.java7OperateSpark; import java.util.Arrays; import java.util.L ...
- 关于mysql下hibernate实体类字段与数据库关键字冲突的问题
好久没写了,都忘记博客了,趁着现在还在公司,写的东西是经过验证的,不是在家凭记忆力写的,正确率有保障,就说说最近遇到的一件事情吧. 以前一直用的oracle数据库,这次项目我负责的模块所在的系统是用的 ...
- [WinForm] 使用反射将业务对象绑定到窗体或控件容器
在WebForm中,可以使用反射将业务对象绑定到 ASP.NET 窗体控件.最近做Winform项目,也参考WebForm中的代码实现同样的功能. Winform没有提供类似WebForm中的 ...