我得到一个问题,获取删除按钮编辑一次点击。问题在于它根本没有出现。我的代码在下面,它适用于在单元格中滑动...提前感谢您的帮助!删除按钮不会出现在UITableViewCell
#import "ViewController.h"
@interface ViewController()
@property (strong) NSArray *lessons;
@end
static NSString *identifier = @"Cell";
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.lessons = @[
@"Computer Science",
@"Math",
@"Chemistry"
];
self.tableView = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStylePlain];
self.tableView.dataSource = self;
self.tableView.delegate = self;
[self.view addSubview:self.tableView];
self.navigationItem.rightBarButtonItem = self.editButtonItem;
[self.tableView registerClass:UITableViewCell.class forCellReuseIdentifier:identifier];
}
#pragma mark - Table view data source
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return self.lessons.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
cell.textLabel.text = self.lessons[indexPath.row];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
return cell;
}
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
return YES;
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
}
#pragma mark - Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
return UITableViewCellEditingStyleDelete;
}
@end
一旦我按下编辑按钮。
当我滑过手机时出现这种情况。
如何创建编辑按钮? – pbasdf 2014-10-11 12:46:32
感谢您的评论,我已经解决了这个问题! – Majotron 2014-10-11 13:26:30