【问题标题】:UIPopover crashing from UIButtonUIPopover 从 UIButton 崩溃
【发布时间】:2011-10-29 00:16:59
【问题描述】:

我正在通过 UIButton 呈现 UIPopover,但我的应用程序在 [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];
}

【问题讨论】:

    标签: iphone objective-c cocoa-touch uibutton uipopovercontroller


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

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

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2015-04-12
        • 2015-06-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多