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

标签 ios ipad actionview popover

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 方法中并通过弹出窗口中的按钮触发它,它会顺利运行!

最佳答案

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

关于ios - 在 Popover 中显示 ActionSheet——我做错了什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6602589/

相关文章:

ios - CLLocationManager弹出窗口

iphone - 您如何在 Master-Detail Storyboard模板中访问 tableView?

iphone - 从自定义类中获取特定类型的属性

ruby-on-rails - 将类添加到生成的表单的正确 button_to 语法是什么?

ios - 为什么 swift 隐藏受限协议(protocol)的默认实现?

ios - 在 Swift 中使用自定义运算符优于方法的优势

ios - swift 中的相同数据类型多变量声明

ios - 无法以任何新方法更改 socket 的属性

ruby-on-rails - 如何测试 Rails 插件中的 View ?

ruby-on-rails - Rails 3中的动态错误页面