【发布时间】:2015-01-12 12:45:46
【问题描述】:
真的很奇怪。 :(
我正在尝试在 tableview 中实现滑动删除。因为这就是我所拥有的。
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
return YES;
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@"commitEditingStyle===%@", editingStyle);
if (editingStyle == UITableViewCellEditingStyleDelete) {
//add code here for when you hit delete
NSLog(@"now delete this cell");
}
}
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
return UITableViewCellEditingStyleDelete;
}
当我滑动时,滑动完成,但我看不到删除按钮。
知道发生了什么吗?
编辑 1
现在更奇怪了。
当我在viewDidLoad 中说mainTableView.editing = YES; 时,我有以下内容。
为什么左侧出现删除选项?
还有编辑选项,它仍然和第一张图片一样。
编辑 2
// table view delegates
- (int)numberOfSectionsInTableView:(UITableView *) tableView {
return 1;
}
- (int) tableView:(UITableView *) tableView numberOfRowsInSection:(NSInteger)section {
return actualProductsArray.count;
}
-(UITableViewCell *) tableView:(UITableView *) tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MainCell"];
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"MainCell"];
// created label and added into cell...
cell.backgroundColor = [UIColor clearColor];
cell.contentView.backgroundColor = [UIColor clearColor];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}
【问题讨论】:
-
也许这个答案可能会有所帮助:stackoverflow.com/q/19645356/2274694
-
@LyndseyScott:看我的更新......有些奇怪......
-
mainTableView.editing = YES不会解决问题。 -
@Harry :我添加了该选项只是为了看看根据以下答案会发生什么......
-
@Harry:知道为什么会这样吗?
标签: ios objective-c uitableview swipe