Ios4 iOs-进入编辑模式时隐藏按钮
我有一个UITableView,每个UITableviewCell包含2个按钮。 当UITableview处于编辑模式时,如何隐藏按钮?Ios4 iOs-进入编辑模式时隐藏按钮,ios4,uitableview,Ios4,Uitableview,我有一个UITableView,每个UITableviewCell包含2个按钮。 当UITableview处于编辑模式时,如何隐藏按钮? 谢谢我建议您将UITableViewCell子类化,并将按钮添加为属性,然后将其隐藏的属性设置为“是”: @interface CustomCell: UITableViewCell { UIButton *btn1; UIButton *btn2; } @property (nonatomic, readonly) UIButon *btn
谢谢我建议您将UITableViewCell子类化,并将按钮添加为属性,然后将其
隐藏的属性设置为“是”:
@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];
}
希望有帮助。只是想用更简单的解决方案更新此线程。为了隐藏UITableViewCell
的自定义子类中的特定元素,只需覆盖UITableViewCell
的一个方法(在Swift中实现):
调用父级UITableView
的-setEditing:animated:
方法后,将自动为每个单元格调用此函数 谢谢@H2CO3,当我更新一个单元格时,它可以工作,但是你知道当所有单元格都处于编辑模式时如何应用此方法吗?(意思是当“减号”按钮出现在所有行上时?)我找到了隐藏按钮的方法:-(UITableViewCellEditingStyle)tableView:(UITableView*)tableView editingStyleForRowAtIndexPath:(NSIndexPath*)indexPath{[(CustomCell*)[tableView cellForRowAtIndexPath:indexPath]hideButtons];返回UITableViewCellEditingStyleDelete;}但我不知道在我离开编辑模式时是否会显示它们。无论如何,在更新单元格时不会调用此方法。它在其他委托方法中被调用。
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
}