Sams **在 24 小时内自学 iPad 应用程序开发说我可以“以‘非动画’方式显示操作表,当它第一次出现时填充完整的弹出 View ...为此,您需要显示带有方法的操作表
showFromRect:inView:animated
将“rect”设置为弹出框的尺寸,将 View 设置为弹出框 View Controller 的 View ,并将“animated”设置为 false。操作表的显示需要在首次加载弹出 View 时发生,例如在弹出 View Controller 的 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 方法中并通过弹出窗口中的按钮触发它,它会顺利运行!
最佳答案
一种解决方案是在viewWillAppear
或viewDidAppear
中调用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];
}
关于ios - 在 Popover 中显示 ActionSheet——我做错了什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6602589/