2012-05-03 25 views
1

嗨,大家好,我有這個我IBAction爲連接到一個按鈕:clickedButtonAtIndex:不工作

- (IBAction)showCurl:(id)sender { 
     alert1 = [[UIAlertView alloc]initWithTitle:@"Loading" message:nil delegate:self cancelButtonTitle:nil otherButtonTitles:nil]; 
     [alert1 show]; 

}

和clickedButtonIndex自動運行但不知何故,它不會加載SecondViewController:

#pragma mark UIAlertView 
- (void)alertView:(UIAlertView *)alert1 clickedButtonAtIndex:(NSInteger)buttonIndex { 
    if(buttonIndex == 0){ 
     SecondViewController *sampleView = [[SecondController alloc] init]; 
     [sampleView setModalTransitionStyle:UIModalTransitionStylePartialCurl]; 
     [self presentModalViewController:sampleView animated:YES]; 
     } 
    else{ 
      // Cancel prompt 
     } 
} 

我在這裏錯過了什麼?

+0

什麼問題?警報是否顯示?如果是這樣,是否調用了委託方法? –

+0

顯示警告,但不會切換到反映在 - (void)alertView中的SecondViewController:(UIAlertView *)alert1 clickedButtonAtIndex:(NSInteger)buttonIndex {' –

回答

2

如果您不提供警報視圖中的某些按鈕標題,將不會有任何按鈕點擊並且委託方法不會被調用。

- (IBAction)showCurl:(id)sender { 
     alert1 = [[UIAlertView alloc] initWithTitle:@"Loading" message:nil delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; 
     [alert1 show]; 
} 
+0

因此,當用戶單擊按鈕時,我該如何做?警報彈出加載並在數據加載後關閉? –

+1

完全取決於您如何加載數據,但是當您開始時會顯示一個視圖,並在響應「-didFinishLoading」委託回調或某些其他通知時將其解除。 UIAlertView也是錯誤的用戶界面組件;應該謹慎使用,以向用戶提供選擇。一般來說,您應該避免在加載內容時使用模式視圖阻止主UI,特別是在iOS上。 –

0

您的代碼並不顯示一個按鈕

alert1 = [[UIAlertView alloc]initWithTitle:@"Loading" message:nil delegate:self cancelButtonTitle:**nil** otherButtonTitles:**nil**]; 

您傳遞零作爲cancelButtonTitle和nil爲otherbuttonTitles,你至少應該有一個按鈕,標題設置。