繁体   English   中英

从目标C中的另一个按钮打开按钮

[英]Turn a button on from another button in objective C

我如何从第二个按钮开启第一个按钮[self firstButton:sender.enabled = Yes]; 只能将其关闭。 哪个编译器给我一个关于按此方式关闭按钮的警告。 所以,如果有更好的方法从第二个按钮关闭它,请让我知道如何打开和关闭它..

-(IBAction)firstButton:(UIButton *)sender{
if(firstButton is clicked){
//Turn firstButton off
((UIButton *)sender).enabled = NO;
}
}

-(IBAction)secondButton:(UIButton *)sender{
if(secondButton is clicked)
{
//Turn firstButton BACK ON?
[self firstButton:sender.enabled = Yes];
}
}

谢谢!!

您可以使用IBOutlet为每个按钮设置ivars

IBOutlet UIButton *firstButton, *secondButton;

然后将它们链接到Interface Builder中的正确按钮。

然后,您可以使用这些IBActions来完成您正在寻找的内容。

-(IBAction)firstButtonClicked:(id)sender
{
    [firstButton setEnabled:NO];
}

-(IBAction)secondButtonClicked:(id)sender
{
    [firstButton setEnabled:YES];
}

您是否尝试从每个按钮切换另一个按钮的状态? 如果是这样,这应该有所帮助。 首先使用viewWithTag:获取对其他按钮的引用。 这将要求您正确地将每个按钮的标记属性分配给下面指定的相同标记。 然后,您只需将按钮启用状态设置为! 其当前启用状态。 哪个会切换它。 开到关,关到开。

-(IBAction)firstButton:(UIButton *)sender
{
    UIButton *otherButton = (UIButton *)[self.view viewWithTag:33];
    [otherButton setEnabled:!otherButton.enabled];
}

-(IBAction)secondButton:(UIButton *)sender
{
    UIButton *otherButton = (UIButton *)[self.view viewWithTag:44];
    [otherButton setEnabled:!otherButton.enabled];
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM