2012-01-13 57 views
1

我遇到一些麻煩,無論是UIAlertViewUIActionSheet偷重點不放手後鎖定。查看UIActionSheet或UIAlertView中(iPhone/iPad的)

詳細說明,我有一個用戶按下按鈕的設置。然後顯示帶有UITextField的UIAlertView。當用戶按下「確定」按鈕時,會顯示一個UIActionSheet(從UIAlertView委託方法調用),以確認與用戶有關的事情。但是,當他們按下其中一個按鈕時,UIActionSheet會消失,但焦點不會返回到主視圖。

我一直在玩,無論我似乎做什麼我總是以我的主要UIView被這樣的圖層覆蓋(顯然你可以看起來像我通過圖層)。我試圖刪除視圖的所有子視圖,但它沒有任何成功。

enter image description here

請有人可以幫我嗎?

這裏是源代碼:

// This method displays the UIAlertView which contains a UITextView linked up to a 
// UIPickerView. 
- (IBAction)buttonPressed:(id)sender 
{ 
    UIAlertView *deleteAlert = [[UIAlertView alloc] initWithTitle:@"Delete Something" 
                  message:@"Select something to delete:" 
                 delegate:self 
               cancelButtonTitle:@"Cancel" 
               otherButtonTitles:@"Ok", nil]; 
    deleteAlert.alertViewStyle = UIAlertViewStylePlainTextInput; 
    deleteAlert.tag = kDeleteAlert; 
    deleteTextField = [deleteAlert textFieldAtIndex:0]; 
    [pickerView reloadAllComponents]; 
    deleteTextField.inputView = pickerView; 
    [deleteAlert show]; 
} 


// The UIAlertView delegate method is then used to display a UIActionSheet to confirm 
// whether the user wants to proceed. 
- (void) alertView:(UIAlertView *)alert clickedButtonAtIndex:(NSInteger)buttonIndex 
{ 
    UIActionSheet *confirmDelete = [[UIActionSheet alloc] initWithTitle:@"Delete blah?" 
                   delegate:self 
                 cancelButtonTitle:@"No" 
               destructiveButtonTitle:@"Yes" 
                 otherButtonTitles:nil]; 
    confirmDelete.actionSheetStyle = UIActionSheetStyleBlackOpaque; 
    [confirmDelete showInView:self.parentViewController.tabBarController.view]; 
} 

// Then the focus should be returned to the original view (i.e. where the first button 
// was pressed to launch the UIAlertView. However the focus is still locked and the 
// view appears slightly dimmed around the edges. 
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex 
{ 
    if (buttonIndex == actionSheet.destructiveButtonIndex) 
    { 
     // Do some stuff ... 
    } 
} 

回答

2

我覺得你的問題是,當actionSheet被稱爲不被解僱的deleteAlert警報視圖的結果。

我聽起來好像警報視圖仍然具有焦點,但處於未知狀態,因爲它沒有被解僱,但你做了什麼與它的按下按鈕。

想必,你想呈現的動作片時解除警報的看法?那麼當行動表被解僱時,你會回到你的主要觀點?所以,爲了你想要的:

1)當前警報視圖

2)如果在警報視圖按鈕被按下時,它會通知它的委託使用- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex

3)駁回alertView - (void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)animated和現在行動表。

3)當使用操作表時,它會調用它的代理方法- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex,並在該方法中將其解除,或者執行其他任何操作。

你會把所有這些委託方法在您的原始調用視圖控制器,它符合<UIAlertViewDelegate, UIActionSheetDelegate>

你需要使原來的ViewController警報視圖的委託和動作片,當你創建它們。我希望這是有道理的。

更多信息http://developer.apple.com/library/ios/#documentation/uikit/reference/UIAlertView_Class/UIAlertView/UIAlertView.html

+0

非常感謝你的幫助!我真的很感激它 - 我是如此堅持這個問題。 – 2012-01-14 13:01:02

+0

我更新了我的答案,很高興幫助 - 歡呼聲。 – Skybird 2012-01-14 13:14:45

0

我會說這可能是B/C你是不是辭職的UITextField那是UIAlertView中的第一個響應者。請確保您展示在你的UIActionSheet你做

[myTextField resignFirstResponder]; 
+0

感謝您的評論。我剛剛嘗試了你的建議沒有成功:(我也更新了我的問題的源代碼,也許它可能有幫助嗎? – 2012-01-13 22:26:36