ios UITableView实现单击提示,滑动删除,多选行等操作
来源:互联网 发布:犀牛o2o源码 编辑:程序博客网 时间:2024/06/16 01:49
demo功能:ios UITableView实现单击提示,滑动删除,多选行等操作。iphone 6.1测试通过。
demo说明:DeleteMeController.m;CheckListController.m这些都是用UITableView实现的效果代码。
demo截屏:
demo主要代码:
1
#import "DeleteMeController.h"
2
3
@implementation DeleteMeController
4
@synthesize list;
5
-(IBAction)toggleEdit:(id)sender {
6
[self.tableView setEditing:!self.tableView.editing animated:YES];
7
}
8
#pragma mark -
9
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
10
if
(self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
11
// Initialization code
12
}
13
return
self;
14
}
15
16
- (
void
)viewDidLoad {
17
NSString *path = [[NSBundle mainBundle] pathForResource:
@"computers"
ofType:
@"plist"
];
18
NSMutableArray *array = [[NSMutableArray alloc] initWithContentsOfFile:path];
19
self.list = array;
20
21
UIBarButtonItem *editButton = [[[UIBarButtonItem alloc]
22
initWithTitle:
@"Delete"
23
style:UIBarButtonItemStyleBordered
24
target:self
25
action:@selector(toggleEdit:)] autorelease];
26
self.navigationItem.rightBarButtonItem = editButton;
27
28
[super viewDidLoad];
29
}
30
31
32
#pragma mark -
33
#pragma mark Table Data Source Methods
34
- (NSInteger)tableView:(UITableView *)tableView
35
numberOfRowsInSection:(NSInteger)section {
36
return
[list count];
37
}
38
- (UITableViewCell *)tableView:(UITableView *)tableView
39
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
40
41
static
NSString *DeleteMeCellIdentifier =
@"DeleteMeCellIdentifier"
;
42
43
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:DeleteMeCellIdentifier];
44
if
(cell == nil) {
45
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero
46
reuseIdentifier:DeleteMeCellIdentifier] autorelease];
47
}
48
NSInteger row = [indexPath row];
49
cell.text = [self.list objectAtIndex:row];
50
return
cell;
51
}
52
53
#pragma mark -
54
#pragma mark Table Delegate Methods
55
- (
void
)tableView:(UITableView *)tableView
56
commitEditingStyle:(UITableViewCellEditingStyle)editingStyle
57
forRowAtIndexPath:(NSIndexPath *)indexPath {
58
59
NSUInteger row = [indexPath row];
60
[self.list removeObjectAtIndex:row];
61
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]
62
withRowAnimation:UITableViewRowAnimationFade];
63
}
64
65
@end
66
67
#import "DeleteMeController.h"
68
69
@implementation DeleteMeController
70
@synthesize list;
71
-(IBAction)toggleEdit:(id)sender {
72
[self.tableView setEditing:!self.tableView.editing animated:YES];
73
}
74
#pragma mark -
75
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
76
if
(self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
77
// Initialization code
78
}
79
return
self;
80
}
81
82
- (
void
)viewDidLoad {
83
NSString *path = [[NSBundle mainBundle] pathForResource:
@"computers"
ofType:
@"plist"
];
84
NSMutableArray *array = [[NSMutableArray alloc] initWithContentsOfFile:path];
85
self.list = array;
86
87
UIBarButtonItem *editButton = [[[UIBarButtonItem alloc]
88
initWithTitle:
@"Delete"
89
style:UIBarButtonItemStyleBordered
90
target:self
91
action:@selector(toggleEdit:)] autorelease];
92
self.navigationItem.rightBarButtonItem = editButton;
93
94
[super viewDidLoad];
95
}
96
97
98
#pragma mark -
99
#pragma mark Table Data Source Methods
100
- (NSInteger)tableView:(UITableView *)tableView
101
numberOfRowsInSection:(NSInteger)section {
102
return
[list count];
103
}
104
- (UITableViewCell *)tableView:(UITableView *)tableView
105
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
106
107
static
NSString *DeleteMeCellIdentifier =
@"DeleteMeCellIdentifier"
;
108
109
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:DeleteMeCellIdentifier];
110
if
(cell == nil) {
111
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero
112
reuseIdentifier:DeleteMeCellIdentifier] autorelease];
113
}
114
NSInteger row = [indexPath row];
115
cell.text = [self.list objectAtIndex:row];
116
return
cell;
117
}
118
119
#pragma mark -
120
#pragma mark Table Delegate Methods
121
- (
void
)tableView:(UITableView *)tableView
122
commitEditingStyle:(UITableViewCellEditingStyle)editingStyle
123
forRowAtIndexPath:(NSIndexPath *)indexPath {
124
125
NSUInteger row = [indexPath row];
126
[self.list removeObjectAtIndex:row];
127
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]
128
withRowAnimation:UITableViewRowAnimationFade];
129
}
130
131
@end
0 0
- ios UITableView实现单击提示,滑动删除,多选行等操作
- ios UITableView实现单击提示,滑动删除,多选行等操作
- [IOS]UITableView实现Cell的滑动删除
- iOS UITableView实现滑动删除、增加、多选
- IOS 开发使用UITableView 实现滑动 删除等多个按钮
- UITableView 实现滑动删除
- UITableView滑动删除的实现
- [iOS]UITableView滑动删除按钮样式改变
- iOS中uitableview滑动删除添加按钮
- IOS UITableView删除增加操作
- UITableView小技巧--实现cell向左滑动删除,编辑等功能
- UITableView小技巧--实现cell向左滑动删除,编辑等功能
- UITableView实现Cell的滑动删除
- UITableView实现Cell的滑动删除
- UITableView实现Cell的滑动删除
- js实现删除等其他操作弹出的提示框
- 滑动删除uitableview cell
- UITableView 滑动删除数据
- 隐形变量赋值,隐藏参数,隐藏传参
- 2016sdau课程练习专题二 1020
- 345. Reverse Vowels of a String 【E】
- mysql一些实用的语句
- DayDayUP_Linux运维学习_oracle11g安装教程
- ios UITableView实现单击提示,滑动删除,多选行等操作
- ACM2-1003
- PHP是什么
- 测试总结
- HttpClient + Jsoup 网页数据抓取
- 暴搜 bnu51645 ACM Battle
- 指派问题匈牙利解法以及其优化
- Android学习(41) -- 自定义控件(5)图片轮播(伪循环)
- Adobe Photoshop CS5如何调出标尺和网格