【问题标题】:last Button of actionsheet does not get clicked操作表的最后一个按钮没有被点击
【发布时间】:2010-12-15 07:14:37
【问题描述】:

我在我的项目中使用了一个操作表,当它出现时它显示所有按钮,但最后一个(第 4 个)按钮不响应我的点击(只有一半响应)..

我知道原因是因为我使用了 TabBarController 并且当前类在该标签栏控制器内.... 只有操作表的那部分在选项卡上方做出响应....我的最后一个按钮一半在上方,一半在选项卡栏的顶部

请帮忙

【问题讨论】:

  • 请发布您的一些代码,然后我们可以很容易地帮助您解决它。
  • 如果您使用一些自定义标签栏,您就不能使用任何 showFromTabBar 方法。 stackr 告诉投注答案!
  • @WinDMak3r - 是的,我知道,这就是为什么他得到 32 票的原因 :)

标签: iphone user-interface uitabbarcontroller uiactionsheet


【解决方案1】:

我建议使用这个:

[actionSheet showInView:[UIApplication sharedApplication].keyWindow];

我遇到了与您相同的问题,并使用此方法表明它对我有用。 TabBar 想要保留关键 Window 是什么让您的底部按钮出现在上方,但实际上位于 tabbar 下方。

希望这对你有用..

编辑

如果您使用横向模式并且上述方法不起作用。您可以使用以下修复:

@Vinh Tran: [表 showFromTabBar:self.parentViewController.tabBarController.tabBar]

【讨论】:

  • 这个想法只有在视图不使用横向模式时才有效。在横向模式下,我得到纵向模式下的操作表。所以对于风景,我改用了 [sheet showFromTabBar:self.parentViewController.tabBarController.tabBar]。
  • 我遇到了同样的问题,在我看到@stackr 的答案后,我高兴得跳了起来..谢谢一大堆人..
  • 已更新,现在应该再次正确。 :) @newenglander ... 对将近 3 岁的答案投反对票有点多,您不同意吗?答案是正确的,业主很满意。但为了让其他人开心,我还添加了 Vinh Tran 的答案
【解决方案2】:

您使用什么方法来显示您的操作表。试试showFromTabBar:方法

【讨论】:

  • 我用过-------- UIActionSheet *actionsheet=[[UIActionSheet alloc]initWithTitle:@"Select feed type" delegate:self cancelButtonTitle:nil corruptionButtonTitle:nil otherButtonTitles:@"first ",@"2nd",@"3rd",@"4th",nil]; [动作表 showInView:self.view]; [行动表发布];
  • 尝试使用我建议的方法而不是 showInView:。据我了解,它旨在完全处理您的情况(虽然我自己没有使用过......)
  • 根据您的建议,我使用了以下方法......[actionsheet showFromTabBar:delegate.tabC.tabBar]; ...其中委托是我的委托类的对象,其中 tabbarController tabC ......但是我的程序崩溃了....
  • 以下是错误............2010-12-15 13:18:39.876 BabyCare[6338:207] *** 断言失败 -[UIActionSheet _presentSheetFromView:above :], /SourceCache/UIKit_Sim/UIKit-1261.5/UIActionSheet.m:1715 2010-12-15 13:18:39.878 BabyCare[6338:207] *** 由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“无效”参数不满意:view != nil'
  • 检查delegate.tabC.tabBar 是否不是nil 可能是?我创建了示例项目,该方法在那里工作正常(我在当前视图控制器中使用 self.tabBarController.tabBar 来获取 tabBar)
【解决方案3】:

真正的问题出现了,当您的界面旋转到横向并且父视图控制器对其进行了转换时。相信我,这是一个现实的场景,doh。然后操作表被剪裁,你不能使用 parentViewController 因为它被转换了。避免所有这些问题的解决方案是创建一个新窗口,添加一个可旋转的视图控制器作为 rootViewController 并使用它的视图来显示工作表。

CGRect applicationRect = [[UIScreen mainScreen] bounds];
UIWindow* actionSheetWindow = [[UIWindow alloc] initWithFrame:applicationRect];
RotationViewController* rootViewController = [[RotationViewController alloc] initWithNibName:nil bundle:nil];
actionSheetWindow.rootViewController = rootViewController;
[rootViewController release];
actionSheetWindow.hidden = NO;

UIActionSheet* actionSheet = [[UIActionSheet alloc] initWithTitle:nil];
[actionSheet setCancelButtonWithTitle:@"Cancel" handler:^{
    actionSheetWindow.hidden = YES;
    [actionSheetWindow release];
}];

[actionSheet showInView:rootViewController.view];

上面的代码使用 BlocksKit,但您也可以使用 actionSheet 委托和实例属性来实现。

RotationViewController 只是一个 UIViewController 的子类实现

- (void) viewDidLoad {
   [super viewDidLoad];
   self.view.backgroundColor = [UIColor clearColor];
   self.view.opaque = NO;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
  return YES;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多