UIAlertView - 没有动作为什么?

时间:2012-05-17 19:01:40

标签: iphone xcode action uialertview uiactionsheet

我尝试在点击我的alterView中的按钮后开始一个动作 - 但没有任何反应;-(在同一个viewController中我使用了一个带有几个选项的actionSheet - 这个actionsSheet工作正常,但是alertView不需要。

这是我的代码。杜布格没有错误。怎么了?????谢谢!

在标题中:

#define alertWelcome 1
#define alertFacebook 2
#define alertRecommend 3

在ViewDidLoad中:

if (! hasRanBefore) {
        NSLog(@"else has ran before");
        UIAlertView *alert = [[UIAlertView alloc]                     
                              initWithTitle:NSLocalizedString(@"Headline_firstLaunch", @"Headline")
                              message:NSLocalizedString(@"firstLaunch", @"1.Start - Hilfe") delegate:self 
                              cancelButtonTitle:NSLocalizedString(@"no",@"No")
                              //defaultButton:@"OK" 
                              //alternateButton:@"Cancel"                            
                              otherButtonTitles:/*NSLocalizedString(@"Facebook",@"Login"),*/ nil];
         alert.tag = alertWelcome;       
        [alert show];
        [alert release];

    }

    [NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(fbLogin:) userInfo:nil repeats:NO];

我的方法:

- (void)fbLogin:(id)sender{
    NSLog(@"FB Login Alert");
    if (![facebook isSessionValid]) {

        UIAlertView *popupFacebook =  [[UIAlertView alloc]                     
                                      initWithTitle:NSLocalizedString(@"Headline_FacebookL", @"Headline")
                                       message:NSLocalizedString(@"Facebook-Text", @"1.Start - Hilfe") 
                                       delegate:self
                                       cancelButtonTitle:NSLocalizedString(@"no",@"No")
                                       //defaultButton:@"OK" 
                                       //alternateButton:@"Cancel"                            
                                       otherButtonTitles:NSLocalizedString(@"Facebook",@"Login"), nil];
   // [popupFacebook addButtonWithTitle:NSLocalizedString(@"Facebook",@"Login")];
     popupFacebook.tag = alertFacebook;
    [popupFacebook show];
    [popupFacebook release];

}
}

我的方法:

//First View Alert
-(void)firstActionSheet:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
    NSLog(@"clicking");
    //NSString *title = [actionSheet buttonTitleAtIndex:buttonIndex];

    if (alertView.tag == alertWelcome )  {
        if (buttonIndex == 0) {
            NSLog(@"close");
        }
    }  

    else if (alertView.tag == alertFacebook )  {

        if (buttonIndex == 0) {
            NSLog(@"später");
        }  

        if (buttonIndex == 1) {
            //self.label.text = NSLocalizedString(@"Facebook",@"Login"),
            [self fbActive:nil];
            NSLog(@"Login to FB");
        }  

    }
}

完美的运行行动表:

-(IBAction)inviteFriends:(id)sender {
    UIActionSheet *popupQuery = [[UIActionSheet alloc] 
                                 initWithTitle:NSLocalizedString(@"invite_Headline",@"Erzähle es Deinen Freunden:") 
                                 delegate:self 
                                 cancelButtonTitle:NSLocalizedString(@"invite_cancel",@"Abbrechen") 
                                 destructiveButtonTitle:nil
                                 otherButtonTitles:NSLocalizedString(@"invite_eMail",@"per E-Mail einladen"),
                                 NSLocalizedString(@"invite_SMS",@"per SMS einladen"),
                                 NSLocalizedString(@"vote",@"App bewerten"),
                                 /*NSLocalizedString(@"invite_Facebook",@"Facebook"),*/
                                 NSLocalizedString(@"invite_Twitter",@"Twitter"), nil];
    popupQuery.actionSheetStyle = UIActionSheetStyleBlackOpaque;
    popupQuery.tag = alertRecommend;
    [popupQuery showInView:self.view];
    [popupQuery release];

}

-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
    UIDevice* currentDevice = [UIDevice currentDevice];
    if(currentDevice.userInterfaceIdiom == UIUserInterfaceIdiomPad)  {
        NSLog(@"oh its iPad");




        if (buttonIndex == 0) {
            self.label.text = NSLocalizedString(@"invite_eMail",@"per E-Mail einladen"),
            [self showMailPicker:nil];

        }  
        else if (buttonIndex == 1) {
            self.label.text = NSLocalizedString(@"vote",@"App bewerten"),
            [self bewerten:nil];   
        }
        else if (buttonIndex == 2) {
            self.label.text = NSLocalizedString(@"invite_Twitter",@"Twitter"),
            [self twitter:nil];
        } 
        /*else if (buttonIndex == 3) {
            self.label.text = NSLocalizedString(@"invite_cancel",@"Abbrechen");
        }*/


    }
    else{
        NSLog(@"This is iPhone");

        if (buttonIndex == 0) {
            self.label.text = NSLocalizedString(@"invite_eMail",@"per E-Mail einladen"),
            [self showMailPicker:nil];
            NSLog(@"Mail");

        } else if (buttonIndex == 1) {
            self.label.text =  NSLocalizedString(@"invite_SMS",@"per SMS einladen"),
            [self sendInAppSMS:nil];

        } else if (buttonIndex == 2) {
            self.label.text = NSLocalizedString(@"vote",@"App bewerten"),
            [self bewerten:nil];

        } //else if (buttonIndex == 3) {
        //self.label.text = NSLocalizedString(@"invite_Facebook",@"Facebook"),
        //[self facebook_invite:nil]; 
        //    } 
        else if (buttonIndex == 3) {
            self.label.text = NSLocalizedString(@"invite_Twitter",@"Twitter"),
            [self twitter:nil];

        } /*else if (buttonIndex == 4) {
            self.label.text = NSLocalizedString(@"invite_cancel",@"Abbrechen");
        }*/

    }    
}

1 个答案:

答案 0 :(得分:1)

感谢 - 我是个白痴; - )

此代码工作正常; - )

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
    NSLog(@"clicking");
    //NSString *title = [actionSheet buttonTitleAtIndex:buttonIndex];

    if (alertView.tag == alertWelcome )  {
        if (buttonIndex == 0) {
            NSLog(@"close");
        }
    }  

    else if (alertView.tag == alertFacebook )  {

        if (buttonIndex == 0) {
            NSLog(@"später");
        }  

        if (buttonIndex == 1) {
            //self.label.text = NSLocalizedString(@"Facebook",@"Login"),
            [self fbActive:nil];
            NSLog(@"Login to FB");
        }  

    }
}

格尔茨!