0

单击我的 alterView 中的按钮后,我尝试启动一个操作 - 但没有任何反应;-( 在同一个 viewController 中,我使用了一个带有多个选项的 actionSheet - 这个 actionsSheet 工作得很好,但 alertView 没有。

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

在标题中:

#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");
        }*/

    }    
}
4

1 回答 1

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");
        }  

    }
}

问候!

于 2012-05-18T08:04:32.737 回答