我有一个UITableView包含每个UITableviewCell的2个按钮。 如何在UITableview处于编辑模式时隐藏按钮? 感谢iOs - 进入编辑模式时隐藏按钮
3
A
回答
2
我建议你到子类的UITableViewCell并添加按钮为属性,那么他们hidden
属性设置为YES:
@interface CustomCell: UITableViewCell
{
UIButton *btn1;
UIButton *btn2;
}
@property (nonatomic, readonly) UIButon *btn1;
@property (nonatomic, readonly) UIButon *btn2;
- (void)showButtons;
- (void)hideButtons;
@end
@implementation CustomCell
@synthesize btn1, btn2;
- (id) initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSStrig *)reuseId
{
if ((self = [super initWithStyle:style reuseidentifier:reuseId]))
{
btn1 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
// etc. etc.
}
return self;
}
- (void) hideButtons
{
self.btn1.hidden = YES;
self.btn2.hidden = YES;
}
- (void) showButtons
{
self.btn1.hidden = NO;
self.btn2.hidden = NO;
}
@end
而在你的UITableViewDelegate:
- (void)tableView:(UITableView *)tableView willBeginEditingRowAtIndexPath:(NSIndexPath *)indexPath
{
[(CustomCell *)[tableView cellForRowAtIndexPath:indexPath] hideButtons];
}
- (void)tableView:(UITableView *)tableView didEndEditingRowAtIndexPath:(NSIndexPath *)indexPath
{
[(CustomCell *)[tableView cellForRowAtIndexPath:indexPath] showButtons];
}
希望它能帮助。
2
只是想用一个更简单的解决方案来更新这个线程。为了隐藏的UITableViewCell
自定义子类特定的元素,只需覆盖一个方法UITableViewCell
(斯威夫特实现):
override func setEditing(editing: Bool, animated: Bool) {
super.setEditing(editing, animated: animated)
// Customize the cell's elements for both edit & non-edit mode
self.button1.hidden = editing
self.button2.hidden = editing
}
这将自动为每个单元调用父UITableView
的-setEditing:animated:
方法之后调用。
相关问题
- 1. 如何在UITableViewCell中编辑模式时隐藏按钮
- 2. 启用编辑模式时如何隐藏自定义按钮?
- 3. 空时隐藏编辑按钮
- 4. 按下时隐藏iOS按钮
- 5. JTable - 按Tab键进入编辑模式
- 6. 编辑模式按钮
- 7. 如何在UITableViewCell进入/退出编辑模式时隐藏/显示控件?
- 8. iOS倒计时显示隐藏按钮
- 9. 如何通过代码隐藏为gridview编辑编辑按钮?
- 10. Magento删除(显示/隐藏编辑器)按钮管理模块
- 11. 导航控制器上的编辑按钮不会进入编辑模式
- 12. 进入UIImagePickerController编辑模式
- 13. 同时进入编辑模式的UITableViewCell
- 14. 设置为隐藏后隐藏的按钮不隐藏 - IOS
- 15. Dynamics AX 2012:在AxGridView编辑模式下,如何隐藏保存按钮
- 16. 以编程方式隐藏和取消隐藏按钮
- 17. 按下按钮时启用tableView的编辑模式
- 18. 添加左按钮时隐藏返回按钮ios
- 19. 隐藏输入按钮
- 20. iOS编辑按钮执行
- 21. 暂时隐藏UINavigationBar按钮
- 22. 隐藏按钮
- 23. 隐藏按钮
- 24. 编辑内容时隐藏键盘UIWebView
- 25. 隐藏标签和显示按钮ios
- 26. Xamarin IOS隐藏栏后退按钮
- 27. 如何在未处于编辑模式时隐藏插入符号?
- 28. GridView - 使用代码隐藏复选框(按钮单击)将多行输入编辑模式
- 29. Odoo如何隐藏基于用户组的编辑按钮?
- 30. 在选定的UITABLEVIEW单元上隐藏/禁用编辑按钮?
感谢@ H2CO3,它适用于我更新单个单元格时,但是当您想要在所有单元格处于编辑模式时应用此方法吗? (意思是当所有行上出现“减号”按钮时)? – Stan92
我发现这隐藏按钮: - (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath :(NSIndexPath *)indexPath {(CustomCell *) [tableView cellForRowAtIndexPath:indexPath] hideButtons]; return UITableViewCellEditingStyleDelete; } 但是,当我离开编辑模式时,不知道将它们显示出来。 – Stan92
无论如何,当您更新单元格时不会调用此方法。它在其他委托方法中被调用。 – 2012-01-21 21:23:49