2014-10-01 47 views
0

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

这是代码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 {} 

}

预先感谢您

回答

0

尝试移动方法调用您的密码在

-(void)viewDidAppear:(BOOL)animated 
{ 

} 

或者对你的方法提一些参考。

+0

谢谢你的回答。 – dev1001 2014-10-03 13:50:24