FirstApp,iphone开发学习总结11,表操作(移动、删除)
2012-05-10 09:27
615 查看
nav添加左按钮:
- (void)viewDidLoad
{
//...
UIBarButtonItem *tableEditBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemEdit target:self action:@selector(toggleEdit:)];
[[self navigationItem] setLeftBarButtonItem:tableEditBtn];
[tableEditBtn release];
}edit按钮的实现:
- (void)toggleEdit:(id)sender
{
if ([self isEditing]) {
[self setEditing:NO animated:YES];
}else{
[self setEditing:YES animated:YES];//设置编辑状态
}
}表删除:
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete) {
[data removeObjectAtIndex:[indexPath row]];//先移除数据,再移除表里的显示
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES];
}
}表移动:
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath
{
NSArray *moveRow = [data objectAtIndex:[sourceIndexPath row]];//保存移动的行
[data removeObjectAtIndex:[sourceIndexPath row]];//将移动行数据清除,此时移动至的行空缺
[data insertObject:moveRow atIndex:[destinationIndexPath row]];//将数据插入此空缺
}其他未做修改。
求指点。
- (void)viewDidLoad
{
//...
UIBarButtonItem *tableEditBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemEdit target:self action:@selector(toggleEdit:)];
[[self navigationItem] setLeftBarButtonItem:tableEditBtn];
[tableEditBtn release];
}edit按钮的实现:
- (void)toggleEdit:(id)sender
{
if ([self isEditing]) {
[self setEditing:NO animated:YES];
}else{
[self setEditing:YES animated:YES];//设置编辑状态
}
}表删除:
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete) {
[data removeObjectAtIndex:[indexPath row]];//先移除数据,再移除表里的显示
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES];
}
}表移动:
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath
{
NSArray *moveRow = [data objectAtIndex:[sourceIndexPath row]];//保存移动的行
[data removeObjectAtIndex:[sourceIndexPath row]];//将移动行数据清除,此时移动至的行空缺
[data insertObject:moveRow atIndex:[destinationIndexPath row]];//将数据插入此空缺
}其他未做修改。
求指点。
相关文章推荐
- FirstApp,iphone开发学习总结3,UIButton简单的操作
- FirstApp,iphone开发学习总结12,播放音乐、视频
- FirstApp,iphone开发学习总结6,Navigation的使用
- FirstApp,iphone开发学习总结13,方向感应和通告
- FirstApp,iphone开发学习总结
- FirstApp,iphone开发学习总结7,相机
- FirstApp,iphone开发学习总结4,UITextField的值To UILabel
- FirstApp,iphone开发学习总结1,UIview添加UIimage
- FirstApp,iphone开发学习总结8,自定义TablevViewCell
- FirstApp,iphone开发学习总结9,旋转
- FirstApp,iphone开发学习总结10,归档(序列化、固化)
- FirstApp,iphone开发学习总结2,简单的表
- FirstApp,iphone开发学习总结0,创建TabBar
- FirstApp,iphone开发学习总结5,Slider改变Label的值
- iPhone开发入门系列1(iOS8+Swift版)天天打靶APP学习10-11
- PHP 开发 APP 接口 学习笔记与总结 - XML 方式封装通信接口
- 20169205 2016-2017-2 《移动平台应用开发实践》第7周学习总结
- 移动平台前端开发总结(针对iphone,Android等手机)
- [C++再学习系列] STL容器删除操作总结
- 移动平台前端开发总结(针对iphone,Android等手机)