@interface ViewController ()
{
NSMutableArray *vcNrray;
IBOutlet UITableView *vctableview;//tableview的xib
}
@end
@implementation ViewController
- (instancetype)init
{
self = [super init];
if (self) {
vcNrray = [@[@"a",@"b",@"c",@"h",@"d",@"ds",@"sd",@"fd",@"gdd",@"ad"] mutableCopy];
}
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
// Uncomment the following line to preserve selection between presentations.
// self.clearsSelectionOnViewWillAppear = NO;
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
self.navigationItem.rightBarButtonItem = self.editButtonItem;
[vctableview registerNib:[UINib nibWithNibName:@"VCTableViewCell" bundle:nil] forCellReuseIdentifier:@"abab"];
}
-(void)setEditing:(BOOL)editing animated:(BOOL)animated
{
[super setEditing:editing animated:animated];
[vctableview setEditing:editing animated:animated];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [vcNrray count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
VCTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"abab" forIndexPath:indexPath];
cell.cellLabel.text = vcNrray[indexPath.row];
return cell;
}
#pragma mark -
#pragma mark - 移动
//- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
//{
// return UITableViewCellEditingStyleNone;
//}
//
//- (BOOL)tableView:(UITableView *)tableView shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath
//{
// return NO;
//}
//
//- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath
// toIndexPath:(NSIndexPath *)toIndexPath
//{
// id object = [vcNrray objectAtIndex:fromIndexPath.row];
// [vcNrray removeObjectAtIndex:fromIndexPath.row];
// [vcNrray insertObject:object atIndex:toIndexPath.row];
//}
#pragma mark -
#pragma mark - 删除
//-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
//{
//
//
// [vcNrray removeObjectAtIndex:indexPath.row];
// [vctableview deleteRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath, nil] withRowAnimation:UITableViewRowAnimationAutomatic];
//
//}
#pragma mark -
#pragma mark - 添加
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
return UITableViewCellEditingStyleInsert;
}
-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
[vcNrray insertObject:@"111" atIndex:indexPath.row];
[vctableview insertRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath, nil] withRowAnimation:UITableViewRowAnimationAutomatic];
}
iOS-tableview的移动、添加、删除
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
推荐阅读更多精彩内容
- 在此特此声明:一下所有链接均来自互联网,在此记录下我的查阅学习历程,感谢各位原创作者的无私奉献 ! 技术一点一点积...
- 太长了,还是转载吧...今天在看博客的时候,无意中发现了@Trinea在GitHub上的一个项目Android开源...
- 摘录: 天底下只有一种方法可以影响他人,就是提出他们的需要,并让他们知道怎么去获得。 感想: 如果你想让别人做到你...