iOS8应用程序在打开popover时崩溃

时间:2014-11-04 14:52:42

标签: objective-c ios8 popover

这是我编写的代码,当用户选择popover时,它就在方法中:

- (IBAction) onSelectingDefect:(id)sender
    {
        if ([description isFirstResponder]) {
            [self hideKeyBoard];
            return;
        }

        UIButton *button = (UIButton*)(sender);
        UIButton *doneSelectingStatusButton = [UIButton buttonWithType:UIButtonTypeCustom];
        doneSelectingStatusButton.frame = CGRectMake(85, 223, 149, 32);
        [doneSelectingStatusButton setTintColor:[UIColor blackColor]];
        [doneSelectingStatusButton setTitle:@"Done" forState:UIControlStateNormal];
        [doneSelectingStatusButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [doneSelectingStatusButton setBackgroundImage:[UIImage imageNamed:@"cancel_button02.png"] forState:UIControlStateNormal];
        [doneSelectingStatusButton addTarget:self action:@selector(onPickerSelection:) forControlEvents:UIControlEventTouchUpInside];
        UIPickerView *pickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 0, 320, 216)];
        pickerView.showsSelectionIndicator = YES;
        pickerView.delegate = self;
        pickerView.dataSource = self;
        BOOL isNill = TRUE;
        int i;
        for(i=0; i<[tableData count]; i++)
        {
            if([selectedPickerText isEqualToString:[tableData objectAtIndex:i]])
            {
                isNill = FALSE;
                break;
            }
        }
        if(isNill)
        {
            [pickerView selectRow:0 inComponent:0 animated:YES]; //Orig
            //self.selectedPickerText = [tableData objectAtIndex:0];
            self.selectedPickerText = [tableData objectAtIndex:0];
        }
        else
            [pickerView selectRow:i inComponent:0 animated:YES];//Orig

        UIView *containerView = [[UIView alloc] initWithFrame:CGRectMake(0,0, 320, 255)];
        [containerView addSubview:doneSelectingStatusButton];
        [containerView addSubview:pickerView];

        UIViewController *pickerViewController = [[UIViewController alloc] init];
        CGRect myRect = button.frame;
        myRect.origin.x += 10;
        myRect.origin.y += 10;

        selectionPopover  = [[UIPopoverController alloc] initWithContentViewController:pickerViewController];
        ((AppDelegate*) [UIApplication sharedApplication].delegate).secondPopOver = selectionPopover;
        selectionPopover.delegate =self;
        selectionPopover.popoverContentSize  = CGSizeMake(320, 255);
        [selectionPopover presentPopoverFromRect:selectDefect.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES]; //Error iOS8
        pickerViewController.view = containerView;

        [containerView release];
        [pickerView release];
        [pickerViewController release];

    }

这是我正在犯的错误:

2014-11-04 20:01:30.740 Service360[447:5288] -[UITextField length]: unrecognized selector sent to instance 0x7f0d6520
2014-11-04 20:01:30.743 Service360[447:5288] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UITextField length]: unrecognized selector sent to instance 0x7f0d6520'
*** First throw call stack:
(
    0   CoreFoundation                      0x0321f946 __exceptionPreprocess + 182
    1   libobjc.A.dylib                     0x02d01a97 objc_exception_throw + 44
    2   CoreFoundation                      0x032275c5 -[NSObject(NSObject) doesNotRecognizeSelector:] + 277
    3   CoreFoundation                      0x031703e7 ___forwarding___ + 1047
    4   CoreFoundation                      0x0316ffae _CF_forwarding_prep_0 + 14
    5   CoreFoundation                      0x03108d26 CFStringAppend + 374
    6   CoreFoundation                      0x0310684a __CFStringAppendFormatCore + 11754
    7   CoreFoundation                      0x031fc5f5 _CFStringCreateWithFormatAndArgumentsAux2 + 245
    8   Foundation                          0x028b7697 -[NSPlaceholderString initWithFormat:locale:arguments:] + 159
    9   Foundation                          0x028baf42 +[NSString stringWithFormat:] + 89
    10  UIKit                               0x0183dd34 -[UIViewController _presentViewController:withAnimationController:completion:] + 2825
    11  UIKit                               0x018405d2 __62-[UIViewController presentViewController:animated:completion:]_block_invoke + 345
    12  UIKit                               0x01840424 -[UIViewController presentViewController:animated:completion:] + 224
    13  UIKit                               0x01db0791 -[UIPopoverController _presentShimmedPopoverFromRect:inView:permittedArrowDirections:animated:] + 217
    14  UIKit                               0x01db0991 -[UIPopoverController presentPopoverFromRect:inView:permittedArrowDirections:animated:] + 355
    15  Service360                          0x00369b52 -[POVendorFeedbackViewController onSelectingDefect:] + 2770
    16  libobjc.A.dylib                     0x02d177cd -[NSObject performSelector:withObject:withObject:] + 84
    17  UIKit                               0x016da23d -[UIApplication sendAction:to:from:forEvent:] + 99
    18  UIKit                               0x016da1cf -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 64
    19  UIKit                               0x0180de86 -[UIControl sendAction:to:forEvent:] + 69
    20  UIKit                               0x0180e2a3 -[UIControl _sendActionsForEvents:withEvent:] + 598
    21  UIKit                               0x0180d50d -[UIControl touchesEnded:withEvent:] + 660
    22  UIKit                               0x0172a60a -[UIWindow _sendTouchesForEvent:] + 874
    23  UIKit                               0x0172b0e5 -[UIWindow sendEvent:] + 791
    24  UIKit                               0x016f0549 -[UIApplication sendEvent:] + 242
    25  Service360                          0x00068f22 -[MyApplication sendEvent:] + 178
    26  UIKit                               0x0170037e _UIApplicationHandleEventFromQueueEvent + 20690
    27  UIKit                               0x016d4b19 _UIApplicationHandleEventQueue + 2206
    28  CoreFoundation                      0x031431df __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
    29  CoreFoundation                      0x03138ced __CFRunLoopDoSources0 + 253
    30  CoreFoundation                      0x03138248 __CFRunLoopRun + 952
    31  CoreFoundation                      0x03137bcb CFRunLoopRunSpecific + 443
    32  CoreFoundation                      0x031379fb CFRunLoopRunInMode + 123
    33  GraphicsServices                    0x044b424f GSEventRunModal + 192
    34  GraphicsServices                    0x044b408c GSEventRun + 104
    35  UIKit                               0x016d88b6 UIApplicationMain + 1526
    36  Service360                          0x0006793f main + 159
    37  libdyld.dylib                       0x077a7ac9 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

导致应用程序崩溃的行是:

[selectionPopover presentPopoverFromRect:selectDefect.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES]; //Error iOS8

导致此错误的问题是什么?该应用程序在iOS的早期版本或早期版本中运行良好。 你能帮帮我吗?

由于

1 个答案:

答案 0 :(得分:0)

从ios8开始,你需要一个UIPopoverPresentationController用于popovercontroller。

if (  NSClassFromString(@"UIPopoverPresentationController")   ) {

selectionPopover.popoverPresentationController.sourceView = button; //view the popover arrow points to...


}
/// then present popover...