当应用程序来自后台时,栏按钮项不起作用

时间:2014-10-01 16:00:39

标签: ios objective-c xcode

当我点击相同的栏按钮项目时,我尝试执行不同的代码。每当我点击背景图片改变。我检查这是哪一个,然后选择要执行的代码。这是有效的,但当应用程序来自后台时按钮不起作用。一些想法?

这是代码是viewDidLoad:

[self.btnOnOff setImage:[UIImage imageNamed:@"iconON.png"]];
self.btnOnOff.tintColor = [UIColor greenColor];

这是用户点击

时的方法调用
-(IBAction)btnOnOffAction:(id)sender
{
UIImage* selectedImgOFF = [UIImage imageNamed:@"iconOFF.png"];
UIImage* selectedImgON = [UIImage imageNamed:@"iconON.png"];

// UNAVAILABLE
if ([self.btnOnOff.image isEqual:selectedImgON])
{
    //  Ask user confirmation
    self.alertConfirmationStatus = [[UIAlertView alloc] initWithTitle:@"Status of app"   message:@"Do you want to switch to UNAVAILABLE ?" delegate:self cancelButtonTitle:@"No" otherButtonTitles:@"Yes", nil];
    [self.alertConfirmationStatus show];
}

// AVAILABLE
else if ([self.btnOnOff.image isEqual:selectedImgOFF])
{
    //  Ask user confirmation
    self.alertConfirmationStatus = [[UIAlertView alloc] initWithTitle:@"Status of app" message:@"Do you want to switch to \n AVAILABLE ?" delegate:self cancelButtonTitle:@"No" otherButtonTitles:@"Yes", nil];
    [self.alertConfirmationStatus show];
}

else {}

}

提前谢谢

1 个答案:

答案 0 :(得分:0)

尝试在

中移动您的代码
-(void)viewDidAppear:(BOOL)animated
{

}

或对您的方法进行一些参考。