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

时间:2011-07-06 20:33:44

标签: ios ipad actionview popover

Sams **教你自己iPad应用程序开发24小时后说我可以“以非动画”的方式显示一个动作表,在第一次出现时填充一个完整的弹出视图...要做到这一点,你需要显示使用方法的行动表

  

showFromRect:inView:动画

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

好的,很简单..这是我在popover的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方法中并从弹出窗口中的按钮触发它,它可以毫无障碍地工作!

2 个答案:

答案 0 :(得分:2)

一种解决方案是拨打UIActionSheetviewWillAppear中的viewDidAppear:例如:

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

答案 1 :(得分:0)

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

作为一个hacky替代方案,我建议用你的IBAction方法作为回调来缩短(.1秒或者其他)NSTimer