【问题标题】:Show ActionSheet in Popover- what am i doing wrong?在 Popover 中显示 ActionSheet - 我做错了什么?
【发布时间】:2011-07-06 20:33:44
【问题描述】:

Sams **在 24 小时内自学 iPad 应用程序开发说我可以“以“非动画”方式显示操作表,在它首次出现时填充完整的弹出视图...为此,您需要显示带有方法的操作表

showFromRect:inView:animated

“rect”设置为弹出框的尺寸,视图设置为弹出框视图控制器的视图,“动画”设置为 false。首次加载弹出视图时需要显示操作表,例如在弹出视图控制器的 viewDidLoad 方法中。

好的,简单..这是我在弹出框的 viewDidLoad 方法中的代码:

- (void)viewDidLoad {

self.contentSizeForViewInPopover=CGSizeMake(400.0,400.0);


    UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Available Actions" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"Destroy" otherButtonTitles:@"Negotiate", @"Compromise", nil];

    [actionSheet showFromRect:[self.view bounds] inView:self.view  animated:NO];

    [actionSheet release];

    [super viewDidLoad];
}

但这在inView:self.view参数处每次都会失败,但例外:

Invalid parameter not satisfying view != nil

有什么想法吗?

注意,如果我将这个完全相同的代码放在 IBAction 方法中并从弹出窗口中的按钮触发它,它会顺利运行!

【问题讨论】:

  • 在展示 actionSheet 之前尝试调用[super viewDidLoad];
  • @Pengy +1:是的,应该是第一个电话,基本上总是这样。
  • 您是仅在第一次显示视图时尝试执行此操作,还是在显示时执行此操作?
  • 嗨 - 我将 [super viewDidLoad] 移到顶部 - 没有效果。
  • PopOver 视图正在通过我的主视图的 xib 文件中的引用加载。

标签: ios ipad actionview popover


【解决方案1】:

一种解决方案是在viewWillAppearviewDidAppear 中调用UIActionSheet:例如:

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];

    [self showActionSheet];
}

- (void)showActionSheet {
    UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Available Actions" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"Destroy" otherButtonTitles:@"Negotiate", @"Compromise", nil];

    [actionSheet showFromRect:[self.view bounds] inView:self.view  animated:NO];

    [actionSheet release];
}

【讨论】:

  • 为了测试这个理论,我尝试使用 [self.view addSubview] 添加一个 UILabel,效果很好!
  • @PapillonUK:您是否尝试过在 viewWillAppear 中调用 actionSheet?
  • PengOne - 行得通!我以前从未使用过 viewWillAppear - 你能解释一下为什么会这样吗?
  • 好吧,我相信 actionSheet 不能部署到当前不可见的视图上,因为 actionSheet 需要阻止它后面的所有东西。这是一个理论。我会调查一下并更新我的答案。
  • OK PengOne - 我会将其标记为答案。也许山姆的书是不正确的。我还注意到,即使我设置了动画:NO,操作表仍以动画方式向上滚动。我想我在这里处于未知领域——谷歌搜索似乎也找不到太多关于这种方法的信息!感谢您的帮助!
【解决方案2】:

调用此代码时,self.view 尚未完全实例化。

我建议,作为一个 hacky 替代方案,使用您的 IBAction 方法作为回调输入一个短的(0.1 秒左右)NSTimer

【讨论】:

  • 为了测试这个理论,我尝试使用 [self.view addSubview] 添加一个 UILabel,效果很好!
猜你喜欢
  • 1970-01-01
  • 2010-12-03
  • 2022-08-22
  • 2021-04-03
  • 1970-01-01
  • 2015-02-01
  • 2011-06-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多