UIActionSheet 或 UIAlertView (iPhone / iPad) 后视图被锁定
我在 UIAlertView
或 UIActionSheet
窃取焦点而不放开方面遇到了一些麻烦。
详细地说,我有一个用户按下按钮的设置。然后显示一个带有 UITextField 的 UIAlertView
。当用户按下“确定”按钮时,将显示一个 UIActionSheet
(从 UIAlertView
委托方法调用),以向用户确认某些内容。然而,当他们按下其中一个按钮时,UIActionSheet
消失,但焦点不会返回到主视图。
我一直在玩,无论我做什么,我总是以我的主 UIView
被这样的层覆盖(显然你可以通过该层看到我的视图)。我尝试删除视图的所有子视图,但没有成功。
请问有人可以帮助我吗?
这是源代码:
// 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 ...
}
}
I'm having some trouble with either a UIAlertView
or UIActionSheet
stealing the focus and not letting go.
To elaborate, I have a setup whereby a user presses a button. This then displays a UIAlertView
with a UITextField. When the user presses the 'Ok' button a UIActionSheet
is displayed (called from the UIAlertView
delegate method) confirming something with the user. However when they press one of the buttons the UIActionSheet
goes away but the focus doesn't get returned to the main view.
I have been playing around and whatever I seem to do I always end up with my main UIView
being covered with a layer like this (obviously you can seem my view through the layer). I have tried removing all subviews of the view but it didn't have any success.
Please can someone help me out?
Here is the source code:
// 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 ...
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为您的问题是由于调用actionSheet 时deleteAlert 警报视图没有被解除所致。
在我看来,警报视图仍然具有焦点,但处于未知状态,因为它尚未被解除,但您已经通过按下按钮执行了某些操作。
想必您想在呈现操作表时关闭警报视图?然后,当操作表消失时,您会回到主视图吗?因此,您想要的顺序是:
1)显示警报视图
2)如果按下警报视图上的按钮,它会使用
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex< 通知其委托/code>
3) 关闭alertView
- (void)dismissWithClickedButtonIndex:(NSInteger)buttonIndexAnimated:(BOOL)animated
并出示行动表。3)当使用操作表时,它会调用它的委托方法
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
并在该方法中关闭它,或者您其他任何方法需要做的。您可以将所有这些委托方法放入原始调用视图控制器中,使其符合
。创建警报视图和操作表时,您需要使原始视图控制器成为它们的委托。我希望这是有道理的。
更多信息http://developer.apple。 com/library/ios/#documentation/uikit/reference/UIAlertView_Class/UIAlertView/UIAlertView.html
I think your issue is a result of the deleteAlert alert view not being dismissed when the actionSheet is called.
I sounds to me like the alert view still has focus but is in an unknown state, because it hasn't been dismissed, but you have done something with it's button press.
Presumably, you want to dismiss the alert view when the action sheet is presented? Then when the action sheet is dismissed, you get back to your main view? So, the order you want:
1) Present alert view
2) If a button on the alert view is pressed, it notifies it's delegate using
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
3) Dismiss the alertView
- (void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)animated
and present the action sheet.3) When the action sheet is used, it calls it's delegate method
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
and within that method, dismiss it, or whatever else you need to do.You would put all of these delegate methods in your original calling viewcontroller, conforming it to
<UIAlertViewDelegate, UIActionSheetDelegate>
.You will need to make the original viewcontroller the delegate of the alert view AND the action sheet when you create them. I hope this makes sense.
More information http://developer.apple.com/library/ios/#documentation/uikit/reference/UIAlertView_Class/UIAlertView/UIAlertView.html
我想说这可能是因为您没有放弃
UIAlertView
内的UITextField
上的第一响应者。确保在显示UIActionSheet
之前您已这样做I would say it's probably b/c you are not resigning the first responder on the
UITextField
that is inside theUIAlertView
. Make sure that before you show yourUIActionSheet
you do