Bjö*_*ser 8 iphone uitableview ios
在表视图中删除行时,我想显示一个在某些情况下要求确认的操作表.当操作表单以"是"(破坏性操作)回答时,我删除了表格行,一切都很好.但是当按下取消时,我仍然看到处于按下状态的删除按钮.
我在tableView:commitEditingStyle删除时所做的是:
BlockBasedActionSheet *askSheet =
[[BlockBasedActionSheet alloc]
initWithTitle:@"Delete entry?"
cancelButtonTitle:@"No"
destructiveButtonTitle:@"Yes, delete child also records"
cancelAction:^{
UITableViewCell *cell = [self tableView:tableView cellForRowAtIndexPath:indexPath];
if (cell.showingDeleteConfirmation) {
cell.editing = NO;
cell.editingAccessoryView = nil;
cell.editing = YES;
}
}
destructiveAction:deleteBlock];
[askSheet showInView:self.view];
[askSheet release];
Run Code Online (Sandbox Code Playgroud)
同样奇怪的是,单元格的属性showingDeleteConfirmation是NO,但删除按钮仍然可见.
我正在使用自制的基于块的操作表实现.也许存在错误,尽管我似乎在取消块中得到了正确的单元格.
那么,如何将"删除"按钮状态重置为"未按下"并将其删除,并将圆形删除按钮恢复为水平,就像我点击屏幕上的某个位置时一样?
助手班BlockBasedActionSheet.h:
@interface BlockBasedActionSheet : UIActionSheet<UIActionSheetDelegate> {
}
@property (copy) void (^cancelBlock)();
@property (copy) void (^destructiveBlock)();
- (id)initWithTitle:(NSString *)title cancelButtonTitle:(NSString *)cancelButtonTitle destructiveButtonTitle:(NSString *)destructiveButtonTitle cancelAction:(void (^)())cancelBlock destructiveAction:(void (^)())destructiveBlock;
@end
Run Code Online (Sandbox Code Playgroud)
实施文件BlockBasedActionSheet.m:
#import "BlockBasedActionSheet.h"
@implementation BlockBasedActionSheet
@synthesize cancelBlock = _cancelBlock, destructiveBlock = _destructiveBlock;
- (id)initWithTitle:(NSString *)title cancelButtonTitle:(NSString *)cancelButtonTitle destructiveButtonTitle:(NSString *)destructiveButtonTitle cancelAction:(void (^)())cancelBlock destructiveAction:(void (^)())destructiveBlock
{
self = [super initWithTitle:title delegate:self cancelButtonTitle:cancelButtonTitle destructiveButtonTitle:destructiveButtonTitle otherButtonTitles: nil];
if (self) {
_cancelBlock = Block_copy(cancelBlock);
_destructiveBlock = Block_copy(destructiveBlock);
}
return self;
}
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
NSAssert(actionSheet == self, @"Wrong Action Sheet passed");
if (buttonIndex == [self cancelButtonIndex]) {
if (self.cancelBlock) {
self.cancelBlock();
}
} else {
if (self.destructiveBlock) {
self.destructiveBlock();
}
}
}
@end
Run Code Online (Sandbox Code Playgroud)
因此,它的工作原理是用此替换第一个代码片段
BlockBasedActionSheet *askSheet =
[[BlockBasedActionSheet alloc]
initWithTitle:@"Delete entry?"
cancelButtonTitle:@"No"
destructiveButtonTitle:@"Yes, delete also child records"
cancelAction:^{
// this resets the delete button
[tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]
withRowAnimation:UITableViewRowAnimationFade];
}
destructiveAction:deleteBlock];
[askSheet showInView:self.view];
[askSheet release];
Run Code Online (Sandbox Code Playgroud)
重新加载行就可以了。
| 归档时间: |
|
| 查看次数: |
3326 次 |
| 最近记录: |