【发布时间】:2014-10-11 12:36:52
【问题描述】:
我在单击“编辑”时获得“删除”按钮时遇到问题。问题是它根本没有出现。我的代码在下面,它适用于在单元格上滑动...在此先感谢您的帮助!
#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
一旦我按下编辑按钮。
当我在单元格上滑动时出现。
【问题讨论】:
-
如何创建编辑按钮?
-
感谢您的评论,我已经解决了这个问题!
标签: ios uitableview