[英]how to hide or remove UIbutton from headerview
I have a button in headerview of my tableview, its woking fine as well, but problem i am having is: When I want to hide that button on click of another button. 我在tableview的headerview中有一个按钮,它也很好,但我遇到的问题是:当我想要点击另一个按钮时隐藏该按钮。 How can I achieve this?
我怎样才能做到这一点? I have already tried [deletebutton removeFromSuperview];
我已经尝试过[deletebutton removeFromSuperview];
where deleteButton is my buttons name. 其中deleteButton是我的按钮名称。
Here is what I am doing 这就是我在做的事情
-(void)PutTableinEditMode{
DeleteButton=[UIButton buttonWithType:UIButtonTypeCustom]; DeleteButton.frame=CGRectMake(10,1, 65, 25); [DeleteButton setTitle:@"Delete" forState:UIControlStateNormal]; DeleteButton.backgroundColor=[UIColor clearColor]; [DeleteButton addTarget:self action:@selector(DeleteMultipleToDos) forControlEvents:UIControlEventTouchUpInside]; [headerView addSubview:DeleteButton];
DeleteButton=[UIButton buttonWithType:UIButtonTypeCustom]; DeleteButton.frame=CGRectMake(10,1, 65, 25); [DeleteButton setTitle:@"Delete" forState:UIControlStateNormal]; DeleteButton.backgroundColor=[UIColor clearColor]; [DeleteButton addTarget:self action:@selector(DeleteMultipleToDos) forControlEvents:UIControlEventTouchUpInside]; [headerView addSubview:DeleteButton];
DeleteButton=[UIButton buttonWithType:UIButtonTypeCustom]; DeleteButton.frame=CGRectMake(10,1, 65, 25); [DeleteButton setTitle:@"Delete" forState:UIControlStateNormal]; DeleteButton.backgroundColor=[UIColor clearColor]; [DeleteButton addTarget:self action:@selector(DeleteMultipleToDos) forControlEvents:UIControlEventTouchUpInside]; [headerView addSubview:DeleteButton];
DeleteButton=[UIButton buttonWithType:UIButtonTypeCustom]; DeleteButton.frame=CGRectMake(10,1, 65, 25); [DeleteButton setTitle:@"Delete" forState:UIControlStateNormal]; DeleteButton.backgroundColor=[UIColor clearColor]; [DeleteButton addTarget:self action:@selector(DeleteMultipleToDos) forControlEvents:UIControlEventTouchUpInside]; [headerView addSubview:DeleteButton];
DeleteButton=[UIButton buttonWithType:UIButtonTypeCustom]; DeleteButton.frame=CGRectMake(10,1, 65, 25); [DeleteButton setTitle:@"Delete" forState:UIControlStateNormal]; DeleteButton.backgroundColor=[UIColor clearColor]; [DeleteButton addTarget:self action:@selector(DeleteMultipleToDos) forControlEvents:UIControlEventTouchUpInside]; [headerView addSubview:DeleteButton];
DeleteButton=[UIButton buttonWithType:UIButtonTypeCustom]; DeleteButton.frame=CGRectMake(10,1, 65, 25); [DeleteButton setTitle:@"Delete" forState:UIControlStateNormal]; DeleteButton.backgroundColor=[UIColor clearColor]; [DeleteButton addTarget:self action:@selector(DeleteMultipleToDos) forControlEvents:UIControlEventTouchUpInside]; [headerView addSubview:DeleteButton];
}
Then I m having another function as below from where i want to hide this DeleteButton 然后我有另一个功能,如下所示,我想隐藏这个DeleteButton
-(void)DoneEditing { - (void)DoneEditing {
DeleteButton.hidden=YES; [DeleteButton removeFromSuperview];
} }
deletebutton.hidden = YES
if any of those two solution ( removeFromSuperview
and hidden
) do not work, then you certainly don't have the right reference to your button. 如果这两个解决方案中的任何一个(
removeFromSuperview
和hidden
)不起作用,那么你肯定没有对你的按钮的正确引用。 I guess your using nib files to define your views ? 我猜您是使用nib文件定义视图吗? Then be sure the member deleteButton is well "linked" to the actual button.
然后,确保成员deleteButton很好地“链接”到实际按钮。 (ie verify using debug that your deleteButton var is not null)
(即使用调试验证您的deleteButton var不为空)
您可以尝试更改该按钮的文本,因为我正在考虑向nil对象发送消息。
I got the it working actually [DeleteButton removeFromSuperView] is working .. problem was that the first method PutTableinEditMode was being called from somewhere else also, so i simply took a bool variable and on basis of its value added and removed the delete button :) 我得到它的工作实际上[DeleteButton removeFromSuperView]正在工作..问题是第一个方法PutTableinEditMode也被从其他地方调用,所以我只是采取一个bool变量,并根据其添加的值,删除删除按钮:)
Thanks guys for helping though :) Ifeel so stupid to make such a silly mistake :) 谢谢大家的帮助:)尽管犯了这么愚蠢的错误,我感到非常愚蠢:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.