2012-05-17 15 views
0

我嘗試在點擊我的alterView中的按鈕後開始一個動作 - 但沒有任何反應;-(在同一個viewController中,我使用了一個actionSheet有幾個選項 - 這個actionsSheet完美工作,但alertView不會。這裏是我的代碼Dubug沒有錯誤有什麼不對?????謝謝UIAlertView - 沒有動作爲什麼?

在標題:!

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

    } 
} 

完美運行actionSheet:

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

    }  
} 
+2

你有一個名爲'firstActionSheet:clickedButtonAtIndex:'的方法。這是一個錯字嗎? (該委託方法應該是'alertView:clickedButtonAtIndex:'。) –

+0

對不起,我不明白..所以我已經爲actionSheet的一個叫做alertView的方法, - 但我不瞭解我的probelm在alterView – webschnecke

+1

The你發佈的代碼包含一個開始的方法 - (void)firstActionSheet:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {'。我的觀點是,這不是委託方法的名稱。 –

回答

1

謝謝 - 林白癡;-)

氏s代碼正常工作;-)

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

    } 
} 

Greetz!