模态视图控制器出现在操作表后面

发布于 2024-10-07 23:21:03 字数 2315 浏览 3 评论 0原文

我的模态视图控制器显示在 UIActionSheet 后面,并且我的 UIActionSheet 不会被忽略。我正在使用:

[self presentModalViewController:composeTweetView animated:YES];

展示我的模态视图控制器。

我的操作表从 tabBar 显示:

[actionSheet showFromTabBar:self.parentViewController.tabBarController.tabBar];

此代码适用于 iOS 4.0。

if (buttonIndex == 0) {
        if (self.isLoggedIn) {
            [FlurryAPI logEvent:@"ST_REPLY_CLICKED"];
            composeTweetView.isDirectMessage = FALSE;
            [self presentModalViewController:composeTweetView animated:YES];
            [composeTweetView release];
        }
        else {
            LoginViewController* loginView = [[LoginViewController alloc] initWithNibName:@"LoginViewController" bundle:nil];
            loginView.delegate = self;
            loginView.isPostingComment = TRUE;
            self.isReply = TRUE;
            [self presentModalViewController:loginView animated:YES];
            [loginView release];
            [composeTweetView release];
        }
    }

摘要:

我有一个包含 UITabBar 的 UIViewController。我正在呈现一个 UIActionSheet,其中有一些呈现模式视图控制器的按钮。当模态视图控制器出现时,UIActionSheet 应该自行消失,并且模态视图应该位于堆栈的顶部。问题是,UIActionSheet 不会关闭,模态视图会在其后面加载。这个问题直到iOS 4.2.1才出现

重现步骤:

  1. 创建一个TabBar项目,设置 iOS 4.2.1 的基础 SDK
  2. 创建一个按钮或触发器来显示 UIActionSheet
  3. 允许 UIActionSheet 中的按钮之一使用以下语法呈现模式视图控制器: [actionSheet showFromTabBar:self.parentViewController.tabBarController.tabBar] ;

预期结果:

1. The UIActionSheet should dismiss itself, and the modal view should appear in front

实际结果:

1. The UIActionSheet does not get dismissed and the modal view appears behind it.

回归:

This problem was not apparent prior to iOS 4.2.1

注释: 我尝试了其他显示 UIActionSheet 的方法,但所有这些方法都无法按预期工作:

//[actionSheet showInView:self.parentViewController.tabBarController.tabBar];
//[actionSheet showInView:[self.view window]];
//[actionSheet showInView:self.parentViewController.tabBarController.view];
//[actionSheet showInView:[UIApplication sharedApplication].keyWindow];

My modal view controllers are being shown behind my UIActionSheet, and my UIActionSheet is not getting dismissed. I am using:

[self presentModalViewController:composeTweetView animated:YES];

To present my modal view controller.

My action sheet is being shown from the tabBar:

[actionSheet showFromTabBar:self.parentViewController.tabBarController.tabBar];

This code worked on iOS 4.0.

if (buttonIndex == 0) {
        if (self.isLoggedIn) {
            [FlurryAPI logEvent:@"ST_REPLY_CLICKED"];
            composeTweetView.isDirectMessage = FALSE;
            [self presentModalViewController:composeTweetView animated:YES];
            [composeTweetView release];
        }
        else {
            LoginViewController* loginView = [[LoginViewController alloc] initWithNibName:@"LoginViewController" bundle:nil];
            loginView.delegate = self;
            loginView.isPostingComment = TRUE;
            self.isReply = TRUE;
            [self presentModalViewController:loginView animated:YES];
            [loginView release];
            [composeTweetView release];
        }
    }

Summary:

I have a UIViewController that contains a UITabBar. I am presenting a UIActionSheet which has a few buttons that present a modal view controller. When the modal view controller is presented, the UIActionSheet should dismiss itself and the modal view should be on the top of the stack. The problem is, the UIActionSheet does not dismiss, and the modal view is loaded behind it. This problem did not occur up until iOS 4.2.1

Steps to Reproduce:

  1. Create a TabBar project, setting
    your Base SDK to iOS 4.2.1
  2. Create a button or trigger to show a UIActionSheet
  3. Allow one of the buttons in the UIActionSheet to present a modal view controller using the syntax: [actionSheet showFromTabBar:self.parentViewController.tabBarController.tabBar];

Expected Results:

1. The UIActionSheet should dismiss itself, and the modal view should appear in front

Actual Results:

1. The UIActionSheet does not get dismissed and the modal view appears behind it.

Regression:

This problem was not apparent prior to iOS 4.2.1

Notes:
I have tried other ways of displaying the UIActionSheet all of which don't work as intended:

//[actionSheet showInView:self.parentViewController.tabBarController.tabBar];
//[actionSheet showInView:[self.view window]];
//[actionSheet showInView:self.parentViewController.tabBarController.view];
//[actionSheet showInView:[UIApplication sharedApplication].keyWindow];

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

幸福丶如此 2024-10-14 23:21:03

在整理一个示例以重现您的问题时,我查看了 UIActionSheet 委托方法。我相信您可以使用:

actionSheet:didDismissWithButtonIndex:

而不是

actionSheet:clickedButtonAtIndex:

我没有测试过它,但我相信您仍然会得到相同的按钮编号,并且直到操作表从视图中消失之前它不会触发。

In putting together a sample in order to reproduce your problem I took a look at the UIActionSheet delegate methods. I believe you can use:

actionSheet:didDismissWithButtonIndex:

instead of

actionSheet:clickedButtonAtIndex:

I haven't tested it, but I believe you still get the same button number and it doesn't fire until the actionsheet has disappeared from the view.

月牙弯弯 2024-10-14 23:21:03

抱歉,我不明白你的问题,但一切对我来说都很好。我已在模拟器中尝试了以下代码,并在 4.2.1 iPod Touch 4G(均有效)上

- (IBAction)doit {
    UIActionSheet *actionSheet = [[UIActionSheet alloc]initWithTitle:@"title" delegate:self cancelButtonTitle:@"not OK" destructiveButtonTitle:@"Absolutely" otherButtonTitles:nil];
    [actionSheet showFromTabBar:self.tabBarController.tabBar];
    [actionSheet release];
}

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
    if (buttonIndex == 0) {
        UIView *v = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 480)];
        v.backgroundColor = [UIColor redColor];
        [self.view addSubview:v];
        [v release];
    }
}
  1. 创建了 TabBar 示例项目,
  2. 将按钮添加到firstView-nib 并与相应的 IBAction 连接(必须将 < code>FileOwner 到 FirstViewController
  3. FirstViewController.h 中设置委托方法(
  4. 添加上面的代码

/ /编辑:好的,我看到你想以模态方式呈现它,但即使这对我在 4.2.1 上也有效,

TMPController *tmp = [[TMPController alloc]initWithNibName:@"TMP" bundle:nil];
[self presentModalViewController:tmp animated:YES];
[tmp release];

也许它有效,因为我使用 self.tabBarController.tabBar,尝试一下

I don't understand your problem sorry but everything works great for me. I have tried the following code in Simulator and on 4.2.1 iPod Touch 4G (both worked)

- (IBAction)doit {
    UIActionSheet *actionSheet = [[UIActionSheet alloc]initWithTitle:@"title" delegate:self cancelButtonTitle:@"not OK" destructiveButtonTitle:@"Absolutely" otherButtonTitles:nil];
    [actionSheet showFromTabBar:self.tabBarController.tabBar];
    [actionSheet release];
}

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
    if (buttonIndex == 0) {
        UIView *v = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 480)];
        v.backgroundColor = [UIColor redColor];
        [self.view addSubview:v];
        [v release];
    }
}
  1. created the TabBar sample project
  2. added button to firstView-nib and connected with the appropriate IBAction (have to name the FileOwner to FirstViewController)
  3. set the delegate method in FirstViewController.h (<UIActionSheetDelegate>)
  4. added the code above

//EDIT: ok I saw that you want to present it modally but even this works for me on 4.2.1

TMPController *tmp = [[TMPController alloc]initWithNibName:@"TMP" bundle:nil];
[self presentModalViewController:tmp animated:YES];
[tmp release];

maybe it works because I use self.tabBarController.tabBar, try that

把人绕傻吧 2024-10-14 23:21:03

不确定您是否已经解决了这个问题。但我在上面没有看到明确的答案。我遇到了和你完全相同的问题。所以最后,这是我这边的一个问题,但帮助我调试这个问题的是

actionSheet:didDismissWithButtonIndex: 

按照 Matthew 的建议在方法中添加实际的操作代码。

这证明这个观点实际上被驳回了。就在那时,我意识到我将 UIActionSheet alloc 放入了 viewWillAppear 方法中。因此,每次出现视图时,它都会重新创建操作表。

Not sure if you have already resolved this. But I didn't see a clear answer above. I was having exactly the same problem as you. So in the end, it was an issue on my side, but what help me debug this was to add the actual action code in the method

actionSheet:didDismissWithButtonIndex: 

as suggested by Matthew.

This proved that the view was actually dismissed. That's when I realized that I put the UIActionSheet alloc in my viewWillAppear method. So each time the view appears it re-creates the action sheet.

逆光飞翔i 2024-10-14 23:21:03

这看起来很奇怪,正如 SDK 文档所述:

actionSheet:clickedButtonAtIndex:
……
调用此方法后,接收器将自动关闭。

我可以想到它可能不会消失的 3 种可能性:

  1. 处理动画和显示内容的主运行循环(主线程!)没有被调用。您是否在主线程中处理一些繁重的工作,例如同步网络调用? (请注意 SDK 文本中的“之后”一词)
  2. 您以某种方式计划多次显示操作表
  3. 您以模态方式显示相同的视图控制器实例,该实例已经位于视图堆栈上当前视图下方的某个位置。

This seems weird as the SDK Documentation states:

actionSheet:clickedButtonAtIndex:

The receiver is automatically dismissed after this method is invoked.

I can think of 3 possibilities why it may not disappear:

  1. The main runloop (main thread!) which handles the animations and display stuff is not called. Do you work something heavy in your main thread like synchronous networking calls? (note the word "after" in the SDK text)
  2. Somehow you schedule to show the action sheet multiple times
  3. You display the same view controller instance modally that is already somewhere below the current view on the view stack.
残花月 2024-10-14 23:21:03

我刚刚编写了一个快速示例应用程序来测试这一点,它的工作原理正如我预期的那样(即,我无法重现您的问题)。它有点不同,因为我没有制作 TabBar 应用程序,但我仍然希望这会有所帮助。我对 UIActionSheet 所做的就是这样显示:[actionSheet showInView:self.view]。也许这会起作用?

抱歉这么仓促的回答,当我注意到这一点时,我正在出去。 :)

I just wrote a quick sample app to test this out and it worked just as I expected (i.e., I couldn't repro your issue). It was a little different in that I didn't do a TabBar application but I'm still hopeful this helps. What I did with the UIActionSheet was to show it like this: [actionSheet showInView:self.view]. Maybe that will work?

Sorry for the rushed answer, I was on my way out when this caught my eye. :)

扶醉桌前 2024-10-14 23:21:03

我在 iOS 4.2 中也遇到过这样的问题。
我认为您应该尝试执行以下步骤:

  1. 为您想要在单击操作表按钮时执行的代码创建一个单独的方法。假设方法是 -(void)presentModalView{}

2.现在在 - (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex 方法中,调用单击的按钮索引的 presentModalView{} 方法如下:

if(buttonIndex==0)
{
[self performSelector:@selector(presentModalView) withObject:nil afterDelay:0.3];
}

3.您还可以尝试不同的延迟时间。

希望有帮助..

I have also faced problems like this with iOS 4.2.
I think you should try with the following steps:

  1. Create a separate method for the code you want to be executed on clicking the actionsheet button. suppose the method is -(void)presentModalView{}

2.Now in the - (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex method,Call the presentModalView{} method for the clicked button index like this:

if(buttonIndex==0)
{
[self performSelector:@selector(presentModalView) withObject:nil afterDelay:0.3];
}

3.You can also try by different delay time.

Hope it helps..

与酒说心事 2024-10-14 23:21:03

我从 AlertBox/ActionSheet 调用 MailComposeView 时遇到了同样的问题,导致 MailCompseView 出现在不可见屏幕后面。

我通过在actionSheet按钮处理程序中调用dismissWithClickedButtonIndex:animated:解决了这个问题。

I had the same issue calling MailComposeView from AlertBox/ActionSheet caused the MailCompseView to come behind invisible screen.

I solved it by calling dismissWithClickedButtonIndex:animated: in the actionSheet button handler.

紙鸢 2024-10-14 23:21:03

iOS5中该问题已得到解决。

The problem has been resolved in iOS5.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文