2015-07-08 3 views
0

Я пытаюсь создать кнопку в своем приложении, чтобы при нажатии спросит пользователя, хотите ли они добавить картинку, взяв ее или выбрав существующую фотографию из их библиотеки. Я искал все последние несколько дней, и я собрал этот код из нескольких учебников и некоторых других вопросов, заданных на этом сайте. Я имею это в Xcode и подключился к нижней панели. Когда я запускаю симулятор и нажимаю кнопку, приложение зависает или падает. Есть идеи, почему это происходит?UIAlertController не отображает и не отключает/отключает приложение в iOS8

-(IBAction)showAlertAction:(id)sender 
{ 
    UIAlertController * alertController = [UIAlertController alertControllerWithTitle: nil 
                       message: nil 
                     preferredStyle: UIAlertControllerStyleActionSheet]; 
    [alertController addAction: [UIAlertAction actionWithTitle: @"Take Photo" style: UIAlertActionStyleDefault handler:^(UIAlertAction *action) { 

     picker = [[UIImagePickerController alloc]init]; 
     picker.delegate = self; 
     [picker setSourceType:UIImagePickerControllerSourceTypeCamera]; 
     [self presentViewController: picker animated: YES completion:NULL]; 

    }]]; 
    [alertController addAction: [UIAlertAction actionWithTitle: @"Choose Existing Photo" style: UIAlertActionStyleDefault handler:^(UIAlertAction *action) { 

     picker2 = [[UIImagePickerController alloc]init]; 
     picker2.delegate = self; 
     [picker2 setSourceType:UIImagePickerControllerSourceTypePhotoLibrary]; 
     [self presentViewController: picker2 animated: YES completion:NULL]; 

    }]]; 

    alertController.modalPresentationStyle = UIModalPresentationPopover; 

    UIView *senderView = (UIView *) sender; 
    UIPopoverPresentationController * popover = alertController.popoverPresentationController; 
    popover.permittedArrowDirections = UIPopoverArrowDirectionUp; 
    popover.sourceView = senderView; 
    popover.sourceRect = senderView.bounds; 

    [self presentViewController: alertController animated: YES completion: nil]; 
} 

Здесь ошибка приведен в разделе отладки ...

2015-07-08 10:37:13.162 LED Audit[6011:282032] -[UIBarButtonItem bounds]: unrecognized selector sent to instance 0x7b658770 
2015-07-08 10:37:13.518 LED Audit[6011:282032] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIBarButtonItem bounds]: unrecognized selector sent to instance 0x7b658770' 
*** First throw call stack: 
(
    0 CoreFoundation      0x008b9746 __exceptionPreprocess + 182 
    1 libobjc.A.dylib      0x00542a97 objc_exception_throw + 44 
    2 CoreFoundation      0x008c1705 -[NSObject(NSObject) doesNotRecognizeSelector:] + 277 
    3 CoreFoundation      0x00808287 ___forwarding___ + 1047 
    4 CoreFoundation      0x008baede __forwarding_prep_1___ + 14 
    5 LED Audit       0x000570ea -[PictureViewController showAlertAction:] + 1130 
    6 libobjc.A.dylib      0x005587cd -[NSObject performSelector:withObject:withObject:] + 84 
    7 UIKit        0x00c79a90 -[UIApplication sendAction:to:from:forEvent:] + 99 
    8 UIKit        0x00fffbba -[UIBarButtonItem(UIInternal) _sendAction:withEvent:] + 139 
    9 libobjc.A.dylib      0x005587cd -[NSObject performSelector:withObject:withObject:] + 84 
    10 UIKit        0x00c79a90 -[UIApplication sendAction:to:from:forEvent:] + 99 
    11 UIKit        0x00c79a22 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 64 
    12 UIKit        0x00dba18a -[UIControl sendAction:to:forEvent:] + 69 
    13 UIKit        0x00dba5a7 -[UIControl _sendActionsForEvents:withEvent:] + 598 
    14 UIKit        0x00db9811 -[UIControl touchesEnded:withEvent:] + 660 
    15 UIKit        0x00cd1cfa -[UIWindow _sendTouchesForEvent:] + 874 
    16 UIKit        0x00cd27d6 -[UIWindow sendEvent:] + 792 
    17 UIKit        0x00c906d1 -[UIApplication sendEvent:] + 242 
    18 UIKit        0x00ca0b08 _UIApplicationHandleEventFromQueueEvent + 21484 
    19 UIKit        0x00c74337 _UIApplicationHandleEventQueue + 2300 
    20 CoreFoundation      0x007db06f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15 
    21 CoreFoundation      0x007d0b7d __CFRunLoopDoSources0 + 253 
    22 CoreFoundation      0x007d00d8 __CFRunLoopRun + 952 
    23 CoreFoundation      0x007cfa5b CFRunLoopRunSpecific + 443 
    24 CoreFoundation      0x007cf88b CFRunLoopRunInMode + 123 
    25 GraphicsServices     0x03b1f2c9 GSEventRunModal + 192 
    26 GraphicsServices     0x03b1f106 GSEventRun + 104 
    27 UIKit        0x00c78106 UIApplicationMain + 1526 
    28 LED Audit       0x00058d9a main + 138 
    29 libdyld.dylib      0x02c45ac9 start + 1 
    30 ???         0x00000001 0x0 + 1 
) 
libc++abi.dylib: terminating with uncaught exception of type NSException 
(lldb) 
+0

Можете ли вы опубликовать вывод в консоли отладчика, который вы получаете, когда нажимаете кнопку? – jrisberg

ответ

1

Вы не должны использовать элемент кнопки бара как вид, это не так. Исправление очень простое.

UIPopoverPresentationController * popover = alertController.popoverPresentationController; 
popover.permittedArrowDirections = UIPopoverArrowDirectionUp; 
popover.barButtonItem = sender; 
+0

Спасибо! Это решило проблему отображения моего контроллера предупреждений. Однако теперь кнопки не работают и сбой, поэтому на кнопках нужно выполнить некоторые действия. В общем, спасибо! –