UI10_TableView的编辑
来源:互联网 发布:淘宝上的福袋能买吗 编辑:程序博客网 时间:2024/06/03 19:26
#import "MainViewController.h"@interface MainViewController ()<UITableViewDataSource, UITableViewDelegate>@property(nonatomic, retain)UITableView *tableView;@property(nonatomic, retain)NSMutableArray *arr;@end@implementation MainViewController- (void)dealloc{ [_tableView release]; [_arr release]; [super dealloc];}- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{ self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { self.arr = [NSMutableArray arrayWithObjects:@"宋江", @"卢俊义", @"吴用", @"公孙胜", @"关胜", @"林冲", @"秦明" ,@"呼延灼" , @"花容",@"柴进", @"李应", @"朱仝",@"鲁智深",@"武松",nil]; } return self;}- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. self.navigationController.navigationBar.translucent = NO; self.navigationController.navigationBar.barTintColor = [UIColor cyanColor]; // 右边编辑完成按钮.系统自带 self.navigationItem.rightBarButtonItem = self.editButtonItem; self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 375, 667- 64) style:UITableViewStylePlain]; [self.view addSubview:self.tableView]; [_tableView release]; self.tableView.dataSource = self; self.tableView.delegate = self;// //直接打开tableView的编辑按钮模式// [self.tableView setEditing:YES animated:YES];}#pragma mark 重写系统的编辑按钮点击- (void)setEditing:(BOOL)editing animated:(BOOL)animated{ [super setEditing:editing animated:animated]; [self.tableView setEditing:editing animated:YES];}#pragma mark 设置哪些行可以进行编辑,默认YES;-(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath{ return YES;}#pragma mark 有三种样式,一种是插入,一种是删除.默认是删除.还有一个是无.- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{ if (indexPath.row % 2 == 0) { return UITableViewCellEditingStyleInsert; }else{ return UITableViewCellEditingStyleDelete; }}#pragma mark 删除数据 这个方法默认提供了一个左划出来按钮.- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{ if (editingStyle == UITableViewCellEditingStyleDelete) { // 1.删除数据源 [self.arr removeObjectAtIndex:indexPath.row]; // table 删除 [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade]; [tableView reloadData]; // 添加数据 }else if (editingStyle == UITableViewCellEditingStyleInsert){ [self.arr addObject:self.arr[indexPath.row]]; [tableView reloadData]; }}#pragma mark 修改delete按钮标题- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath{ return @"删除";}#pragma mark 这个方法是iOS8.0之后出现的方法,可以在编辑状态的时候有多个按钮.实现置顶与删除
0 0
- UI10_TableView的编辑
- UI10_tableView的编辑
- iOS UI10_tableView的编辑
- UI10_tableview的编辑
- UI10_tableview的编辑
- UI10_TableView的编辑
- UI10_tableView的HeaderView
- 在线编辑fckeditor 的编辑和配置
- 实时编辑表格,可以编辑的表格
- edittext的可编辑和不可编辑
- 搞笑的CSDN编辑
- winrunner的编辑
- 属性编辑的问题
- 属性编辑的问题
- MSFlexGrid的编辑输入
- 可编辑的表头
- 4.5 GPO的编辑
- gcc 的编辑方法
- iis7.5 asp 报错 乱码
- uvalive5987(呃,打表)
- Unable to instantiate application com.Clienta: java.lang.ClassNotFoundErro
- Android viewPager.setOnPageChangeListener()方法过时怎么办
- NGUI_2.6.3_教程四(自定义Atlas,Font)
- UI10_TableView的编辑
- poj 1113 Wall Andrew
- 平庸是因为没有激发潜能
- 大话设计模式之--简单工厂模式
- NGUI_2.6.3_教程五(角色信息跟随)
- 1026. Table Tennis (30)
- c liuchengkongzhi
- 关于css的优先级
- AJAX与spring mvc交互