2012-01-13 45 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