我有一个充当开关的UIButton。 当用户点击它时,它的状态变为“选中”并调用动作“一”。当用户再次点击UIButton状态更改为“未选择”并且该操作不再可用时。
有没有办法通过录制完全不同的UIButton将UIButton设置为“已选择”并将其更改为“已选择”并同时调用相同的操作?
干杯
答案 0 :(得分:1)
从我对这个问题的理解,我想向你提出我的建议
if (!<your_button>.selected)
{
<your_button>.selected = YES;
// do your stuff here
}
else
{
<your_button>.selected = NO;
// do your stuff here, in your case action should be no longer available so that,
<your_button>.userInteractionEnabled = NO;
}
享受编程!
答案 1 :(得分:0)
简单的事情当你点击uibutton为它做一个动作并在该按钮的动作中,你可以将按钮状态设置为选中,然后在下一行代码中你可以调用该方法(动作)
- (IBAction)btn1Touched:(id)sender {
[_btn2 setSelected:YES];
[self btn2Touched:self];
}
- (IBAction)btn2Touched:(id)sender {
NSLog(@"btn Action called");
}
答案 2 :(得分:0)
试试这个,'
-(IBAction)nextbutton:(id)sender{
UIButton *btn=(UIButton *)[self.view viewWithTag:tagValue];//pass tag value of that particuler button
btn.selected=YES;
//do whatevr you want.
}
答案 3 :(得分:0)
UI按钮具有名为selected
的状态,并通过属性selected
然后将按钮设为选定状态
[buttonInstance setSelected:YES];
要取消选择
[buttonInstance setSelected:NO];
答案 4 :(得分:0)
请为该按钮操作编写一个函数,例如
-(void)Buttonaction
{
do your action here
also set your button has selected state.
buttonname.setselected=yes;
}
在选中按钮时调用此功能。
答案 5 :(得分:0)
执行此操作:
-(IBAction)switchButtonClicked:(UIButton*)sender
{
if(sender.isSelected)
{
.....
}
else
{
...
}
[sender setSelected:!sender.isSelected];//This will work as Switch.
}
从
Selected(Switch ON)
设置default(Switch OFF)
UIButton
XIB
属性(图片和标题),或者根据需要设置代码。 只需一个按钮,您就可以使用此代码实现功能