Cell 的增删和移动
来源:互联网 发布:造价员网络培训 编辑:程序博客网 时间:2024/04/28 04:00
// 设置 Cell的 编辑模式 : 删除 。 增加 ,None
#pragma mark -TableView delegate method
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{
if (indexPath.row==1) {
returnUITableViewCellEditingStyleInsert;
}else{
returnUITableViewCellEditingStyleDelete;
}
}
/**
* 2,设置当前视图控制器的"视图"编辑状态
* @param editing 是否设置当前控制器视图为可编辑
* @param animated 是否有动画效果
*
*/
//-(void)setEditing:(BOOL)editing animated:(BOOL)animated{
// if (self.tableView.editing) {
// 为 self.tableView视图 调用 setEditing: 方法后,所有的cell都将触发编辑状态
// [self.tableView setEditing:NO animated:YES];
// }else{
// [self.tableView setEditing:YES animated:YES];
// }
//}
/**
* 设置 该 indexPath.row 是否可被编辑 ;
*/
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
// Return NO if you do not want the specified item to be editable.
if (indexPath.row==0) {
returnNO;
}
return YES;
}
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
// delete row
if (editingStyle ==UITableViewCellEditingStyleDelete) {
// Delete the row from the data source :这行注释非常重要,说明了要在这应该做的操作:1,删除数据 2,移除行
[_fontsArrremoveObjectAtIndex:indexPath.row];
[tableView deleteRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationTop];
}
// insert row
elseif (editingStyle ==UITableViewCellEditingStyleInsert) {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
//同样上面的官方注释已经很清楚的说明了,要添加一行cell要作的步骤:1,添加数据 2,插入行
NSString *newLine=@"New Line";
[_fontsArrinsertObject:newLineatIndex:indexPath.row+1];
NSIndexPath *newIndexPath=[NSIndexPathindexPathForRow:indexPath.row+1inSection:indexPath.section];
[tableView insertRowsAtIndexPaths:@[newIndexPath]withRowAnimation:UITableViewRowAnimationTop];
}
}
/**
* 对Cell 的移动设置
*/
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
{
NSString *testFromIndex=[[_fontsArrobjectAtIndex:fromIndexPath.row]retain];
[_fontsArrremoveObject:testFromIndex];
[_fontsArrinsertObject:testFromIndexatIndex:toIndexPath.row];
}
/**
* 对tableView cell进行有限制的移动设定;
*
*/
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
// Return NO if you do not want the item to be re-orderable.
return YES;
}
对于tableview 的编辑设置方法的分析:
- Cell 的增删和移动
- UitableView的增删和移动
- tableview cell的移动
- //移动cell时的操作
- cell 的选择, 移动 , 删除, 移动, 添加
- UITableVIewcell的增删改 移动
- UICollectionview实现自定义cell的移动删除
- iOS_UITableView 编辑(cell的插入, 删除, 移动)
- iOS UITableView(六) cell的移动
- 可以根随Cell移动的标志
- iOS table简单实现增加移动和删除功能与自定义cell的实现
- iOS开发:UITableView编辑——cell的删除和移动
- UITableView实现选择框和编辑状态时cell向右移动的自定义方法
- UITableView实现选择框和编辑状态时cell向右移动的自定义方法
- IOS开发(28)UITableView之移动Section和Cell
- cell的展开和收起
- 写一个Cell类,有行和列属性,请实现在格子中的上下左右的移动。
- tableView 的 cell 和 cell 的 imageView 的属性
- 深刻认识C++中的public、pivate和protect
- c# 写入异常日志
- Oracle 左连接、右连接、全外连接、(+)号作用
- 代码隐藏 软键盘
- Android NDK学习(4)使用cygwin生成.so库文件
- Cell 的增删和移动
- 求两直线交点
- c++中函数与指向函数的指针
- hdu1813 IDA* 好高端的样子。。。
- 个地方进口货孤苦伶仃烦死了
- IOS越狱开发 root权限获取
- myeclipse 10 安装svn插件
- snmp监控命令
- 苹果CEO库克:下代iPhone6量产蓝宝石屏