ios tableView那些事 (八) tableview的插入移动
来源:互联网 发布:局域网网络管理 编辑:程序博客网 时间:2024/05/05 01:42
在ios基础教程已经出现了这个经典的例子了!我也不费话了发代码!
if (cell == nil)
{
cell = [[UITableViewCellalloc]initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:CellIdentifier];
cell.showsReorderControl =YES; //我们添加一个重新排序控件
}
在导航栏上加个 UIBarButtonItem;
UIBarButtonItem *moveButton = [[UIBarButtonItemalloc]
initWithTitle:@"移动"
style:UIBarButtonItemStyleBordered
target:self
action:@selector(toggleMove)];
self.navigationItem.rightBarButtonItem = moveButton;
事件响应
-(void)toggleMove
{
[self.tableviewsetEditing:!self.tableview.editinganimated:YES]; //初始话时默认不可编辑 点击事件的时候取反 为真!可编辑
if (self.tableview.editing)
{
[self.navigationItem.rightBarButtonItemsetTitle:@"完成"];
}else
{
[self.navigationItem.rightBarButtonItemsetTitle:@"移动"];
}
}
- (BOOL)tableView:(UITableView *)tableView
canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
return YES; //可以移动
}
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
NSUInteger fromRow = [fromIndexPath row]; //要移动的那个cell integer
NSUInteger toRow = [toIndexPath row]; //要移动位置的那个clell integer
//arrayValue 添加数据的那个可变数组
id object = [arrayValueobjectAtIndex:fromRow]; // 获取数据
[arrayValueremoveObjectAtIndex:fromRow]; //在当前位置删除
[arrayValue insertObject:objectatIndex:toRow]; //插入的位置
}
//typedef NS_ENUM(NSInteger, UITableViewCellEditingStyle) {
// UITableViewCellEditingStyleNone,
// UITableViewCellEditingStyleDelete,
// UITableViewCellEditingStyleInsert
-(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
returnUITableViewCellEditingStyleNone; // 这样左边不会出现删除操作时出现的红色按钮
}
- ios tableView那些事 (八) tableview的插入移动
- ios tableView那些事 (八) tableview的插入移动
- ios tableView那些事 (八) tableview的插入移动
- ios tableView那些事 (八) tableview的插入移动
- ios tableView那些事 (八) tableview的插入移动
- ios tableView那些事 (九) tableview的删除
- ios tableView那些事 (十)设置 tableview 的分割线
- ios tableView那些事 (九) tableview的删除
- ios tableView那些事 (十)设置 tableview 的分割线
- ios tableView那些事 (九) tableview的删除
- ios tableView那些事 (十)设置 tableview 的分割线
- ios tableView那些事 (九) tableview的删除
- ios tableView那些事 (十)设置 tableview 的分割线
- ios tableView那些事 (九) tableview的删除
- ios tableView那些事(四)tableView添加标题,头尾和改变cell的宽度---tableview
- ios tableView那些事(二)给tableView添加数据
- ios tableView那些事 (五) 给tableview设置缩进级别
- ios tableView那些事 (七) 给tableView添加响应事件
- ios tableView那些事(三)给tableView添加些图片
- git - 分支管理
- 嵌套矩形 动态规划
- android listview setselection 失效解决办法
- 使用CMake生成VS2010项目查看OpenCV源代码
- ios tableView那些事 (八) tableview的插入移动
- nyoj166 小珂的数学题
- 2-1
- 第五周项目一 体验常成员函数——平面坐标系类
- VC窗口自由的调整大小的实现
- [推荐]如何成为一个早起者。
- ubuntu 安装chrome
- ios tableView那些事 (九) tableview的删除
- BZOJ 1602 Usaco2008 Oct 牧场行走 倍增LCA