由于未捕获的异常'CALayerInvalidGeometry'终止应用程序,原因:'CALayer bounds包含NaN:[0 nan; 240 291]'

时间:2014-01-28 06:57:35

标签: ios iphone objective-c xcode uipopovercontroller

我在UIPopOver中显示PickerView。

为此,我在按钮上单击使用以下代码来显示PopOver。

- (IBAction)btnSelectTeachers:(id)sender {

    UIView *masterView;
    CGRect pickerFrame ;
    if(appDelegate.isOSVersionGreaterThan7)
    {
        masterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 240, 216)];
        pickerFrame = CGRectMake(0, 0, 240, 216);
    }
    else
    {
        masterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 300, 216)];
        pickerFrame = CGRectMake(0, 0, 300, 216);
    }
    UIPickerView *myPicker = [[UIPickerView alloc] initWithFrame:pickerFrame];
    [myPicker setDataSource: self];
    [myPicker setDelegate: self];
    myPicker.tag=3;
    [myPicker selectRow:selectedTeacherIndex inComponent:0 animated:NO];
    [myPicker setShowsSelectionIndicator:YES];
    self.myPickerView=myPicker;
    [masterView addSubview:myPicker];
    UIViewController *viewController = [[UIViewController alloc] initWithNibName:nil bundle:nil];
    viewController.view = masterView;
    viewController.contentSizeForViewInPopover = viewController.view.frame.size;
    self.popoverController =[[UIPopoverController alloc] initWithContentViewController:viewController];
    UIButton *button = (UIButton *)sender;
    [self.popoverController presentPopoverFromRect:button.frame
                                            inView:self.view
                          permittedArrowDirections:UIPopoverArrowDirectionUp
                                          animated:YES];

    [self.myPickerView reloadAllComponents];

    /*if(selectedTeacherIndex<0)
    {
        selectedTeacherIndex=0;
    }*/
    [self.myPickerView selectRow:selectedTeacherIndex+1 inComponent:0 animated:NO];
    [self pickerView:self.myPickerView didSelectRow:selectedTeacherIndex+1 inComponent:0];
}

大多数情况下它的工作正常,但有时会因上述异常而终止。

0 个答案:

没有答案