【问题标题】:iOS8 app getting crash while opening popoveriOS8应用程序在打开弹出窗口时崩溃
【发布时间】:2014-11-04 14:52:41
【问题描述】:

这是我写的代码,它在用户选择弹出框时的方法中:

- (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 版本中运行良好。 你能帮帮我吗?

谢谢

【问题讨论】:

    标签: objective-c ios8 popover


    【解决方案1】:

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

    if (  NSClassFromString(@"UIPopoverPresentationController")   ) {
    
    selectionPopover.popoverPresentationController.sourceView = button; //view the popover arrow points to...
    
    
    }
    /// then present popover...
    

    【讨论】:

    • 你能指导我吗?我尝试使用 pickerViewController 作为弹出框演示控制器,但没有奏效。
    • 粘贴我的答案 if( NSClass ....) 就在你崩溃的行之前 *[selectionPopover present....]
    • 尝试了同样的方法... selectionPopover.popoverPresentationController.sourceView 方法不适用于选择 Popover。
    • pickerViewController 也可以使用同样的方法,但错误依旧存在。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-25
    • 2019-01-07
    • 2016-01-10
    • 2012-09-10
    • 2015-08-30
    • 1970-01-01
    相关资源
    最近更新 更多