UIPopover 从 UIButton 崩溃

发布于 2024-12-12 17:21:03 字数 1163 浏览 0 评论 0原文

我正在从 UIButton 呈现 UIPopover,但我的应用程序在行 [popoverControllerpresentPopoverFromRect:[buttonbounds] inView:button allowedArrowDirections:UIPopoverArrowDirectionRightanimated:NO]; 处崩溃

- (IBAction)birthdayButtonClicked:(id)sender
{
    UIViewController* popoverContent = [[UIViewController alloc] init];
    UIView* popoverView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 344)];
    popoverView.backgroundColor = [UIColor whiteColor];

    UIDatePicker *datePicker = [[UIDatePicker alloc]init];
    datePicker.frame = CGRectMake(0, 44, 320, 300);

    [popoverView addSubview:self.view];
    [popoverView addSubview:datePicker];        
    popoverContent.view = popoverView;

    popoverContent.contentSizeForViewInPopover = CGSizeMake(320, 244);

    UIPopoverController *popoverController = [[UIPopoverController alloc] initWithContentViewController:popoverContent];
    UIButton *button = (UIButton *)sender;
    [popoverController presentPopoverFromRect:[button bounds] inView:button permittedArrowDirections:UIPopoverArrowDirectionRight animated:NO];

    [popoverView release];
    [popoverContent release];
}

I'm presenting a UIPopover from a UIButton but my app is crashing at line [popoverController presentPopoverFromRect:[button bounds] inView:button permittedArrowDirections:UIPopoverArrowDirectionRight animated:NO];

- (IBAction)birthdayButtonClicked:(id)sender
{
    UIViewController* popoverContent = [[UIViewController alloc] init];
    UIView* popoverView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 344)];
    popoverView.backgroundColor = [UIColor whiteColor];

    UIDatePicker *datePicker = [[UIDatePicker alloc]init];
    datePicker.frame = CGRectMake(0, 44, 320, 300);

    [popoverView addSubview:self.view];
    [popoverView addSubview:datePicker];        
    popoverContent.view = popoverView;

    popoverContent.contentSizeForViewInPopover = CGSizeMake(320, 244);

    UIPopoverController *popoverController = [[UIPopoverController alloc] initWithContentViewController:popoverContent];
    UIButton *button = (UIButton *)sender;
    [popoverController presentPopoverFromRect:[button bounds] inView:button permittedArrowDirections:UIPopoverArrowDirectionRight animated:NO];

    [popoverView release];
    [popoverContent release];
}

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

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

发布评论

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

评论(2

你穿错了嫁妆 2024-12-19 17:21:03

添加 self.view 作为子视图不是一个好主意。 UIView 对象在每个当前时刻只能显示一次,不能在 self.view 中显示内容为 self.view 的弹出窗口。如果您确实需要执行此任务,请尝试复制所需的视图。

It is not a good idea to add self.view as subview. UIView object can be displayed only once in every current mooment, you cannot show popover with content as self.view in self.view. If you really need to perform this task then try to make copy of required views.

独守阴晴ぅ圆缺 2024-12-19 17:21:03

将 inView 更改为 self.view。 inView 表示您要在哪个 UIView 中呈现弹出框。

presentPopoverFromRect:[button bounds] inView:**self.view** permittedArrowDirections:UIPopoverArrowDirectionRight animated:NO];

Change the inView to self.view. inView means in which UIView you want to present popover.

presentPopoverFromRect:[button bounds] inView:**self.view** permittedArrowDirections:UIPopoverArrowDirectionRight animated:NO];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文