在 Popover 中显示 ActionSheet - 我做错了什么?

发布于 2024-11-18 22:32:46 字数 1004 浏览 4 评论 0原文

Sams **Teach Yourself iPad 应用程序开发在 24 小时内说我可以“以“非动画”方式显示操作表,在它第一次出现时填充完整的弹出视图......为此,您需要使用以下命令显示操作表方法

showFromRect:inView:动画

“rect”设置为弹出窗口的尺寸,视图设置为弹出窗口视图控制器的视图,“animated”设置为 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 方法中并从弹出窗口中的按钮触发它,则它可以顺利运行!

Sams **Teach Yourself iPad Application development in 24 hour's says I can "display an action sheet in a "nonanimated" fashion, filling a full popover view when it first appears...To do this, you need to show the action sheet with the method

showFromRect:inView:animated

with the "rect" set to the dimensions of the popover, the view set to the popover view controller's view, and "animated" set to false. The display of the action sheet would need to take place when the popover view is first loaded such as in the viewDidLoad method of the popover view controller.

OK, easy.. here's my code in my popover's viewDidLoad method:

- (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];
}

But this fails every time at the inView:self.view parameter with the exception:

Invalid parameter not satisfying view != nil

Any ideas?

Note, if I put this exact same code in an IBAction method and trigger it from a button in the popover, it works without a hitch!

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

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

发布评论

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

评论(2

jJeQQOZ5 2024-11-25 22:32:46

一种解决方案是在 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];
}

One solution is to call the UIActionSheet in viewWillAppear or viewDidAppear: For example:

- (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];
}
请止步禁区 2024-11-25 22:32:46

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

我建议,作为一个 hacky 的替代方案,放入一个短的(0.1 秒或类似的东西)NSTimer 并使用 IBAction 方法作为回调。

self.view hasn't been instantiated completely yet when this code is called.

I would suggest, as a hacky alternative, to put in a short (.1 seconds or something) NSTimer with your IBAction method as the callback.

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