0
我創建了一個警報視圖,要求輸入一些密碼,但我想知道如何僅在單擊「繼續」按鈕時調用方法?從UIAlertView按鈕調用方法
這是我的代碼:
-(IBAction)setUserAlert:(id)sender{
UIAlertView *setPassword = [[UIAlertView alloc] initWithTitle:@"Insert Password" message:nil delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Continue", nil];
//The password isn´t visible.
setPassword.alertViewStyle = UIAlertViewStyleSecureTextInput;
[setPassword show];
// Call the method that i want to call only after you click "Continue".
[self displayMessage:(UIButton *)sender];
}
}
//啓用只有當長度> = 6和密碼匹配
-(BOOL)alertViewShouldEnableFirstOtherButton:(UIAlertView *)alertView{
//Defining the password
NSString *password = [[NSString alloc]initWithFormat:@"12345678"];
UITextField *setPassword = [alertView textFieldAtIndex:0];
if ([setPassword.text length] >= 6 && [setPassword.text isEqualToString:password]){
return YES;
}
return NO;
}
//行動我想打電話給該按鈕,點擊後「繼續」
-(IBAction)displayMessage:(UIButton *)sender{
if ([sender.currentTitle isEqualToString:@"YES"]){
_user.text = [[NSString alloc]initWithFormat:@"Hola Mony"];
_imageUser.hidden = YES;
_goodUser.hidden = NO;
backgound.hidden = YES;
yesButton.hidden = YES;
noButton.hidden = YES;
_userLabel.hidden =YES;
}else{
_user.text = [[NSString alloc]initWithFormat:@"You can´t play"];
_goodUser.hidden = YES;
_imageUser.hidden = NO;
yesButton.hidden = YES;
noButton.hidden = YES;
_userLabel.hidden =YES;
}
}
我想在這個裏面調用「displayMessage」,但我不知道該怎麼做,或者它是否正確。
-(void)alertView:(UIAlertView *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
// the user clicked one of the OK/Cancel buttons
if (buttonIndex == 1){
// call displayMessage, sends and error.
}
}
您必須根據您的要求調用委託方法。 - (void)alertView:(UIAlertView *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex 您的應用程序是否會崩潰。然後運行一次你的應用程序在調試模式,然後它會知道你的應用程序崩潰的委託方法或displaymessage方法 – 2012-01-02 07:48:14
我修復它,忘記「displayMessage」方法,但可能不是最好的方式來做到這一點。 - (IBAction)alertView:(UIAlertView *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex { //用戶點擊確定/取消按鈕 if(buttonIndex == 1){ _user.text = [[NSString alloc ] initWithFormat:@「Hola Mony」]; _imageUser.hidden = YES; _goodUser.hidden = NO; backgound.hidden = YES; yesButton.hidden = YES; noButton.hidden = YES; _userLabel.hidden = YES; } } – unixeO 2012-01-02 08:14:44