在 Popover 中显示 ActionSheet - 我做错了什么?
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一种解决方案是在
viewWillAppear
或viewDidAppear
中调用UIActionSheet
:例如:One solution is to call the
UIActionSheet
inviewWillAppear
orviewDidAppear
: For example:调用此代码时,
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.