在Swift中的UIActivityViewController崩溃

时间:2015-06-27 13:12:49

标签: ios swift uiactivityviewcontroller

当我在这里使用UIActivityViewController activityItems: [self.myimage.image!]时,我的应用程序崩溃了:

let activityViewController = UIActivityViewController(
    activityItems: [self.myimage.image!],
    applicationActivities: nil)

self.presentViewController(activityViewController, animated: true, completion: nil)

myimage定义为UIImageView

@IBOutlet weak var myimage: UIImageView!

堆栈崩溃在这里:

Thread 0 name:
Thread 0 Crashed:
0   MyPictures                  0x000000010008e394 @objc MyPictures.DetailController.ActionShare (My.DetailController)(Swift.AnyObject) -> () + 540 (DetailController.swift:95)
1   UIKit                           0x000000018a5f9400 -[UIApplication sendAction:to:from:forEvent:] + 92 (UIApplication.m:3452)
2   UIKit                           0x000000018a5f9400 -[UIApplication sendAction:to:from:forEvent:] + 92 (UIApplication.m:3452)
3   UIKit                           0x000000018a5e24dc -[UIControl _sendActionsForEvents:withEvent:] + 608 (UIControl.m:647)
4   UIKit                           0x000000018a5f8d9c -[UIControl touchesEnded:withEvent:] + 588 (UIControl.m:417)
5   UIKit                           0x000000018a5b7fbc _UIGestureRecognizerUpdate + 8532 (UIGestureRecognizer.m:347)
6   CoreFoundation                  0x0000000185b3c2a0 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 28 (CFRunLoop.c:1622)
7   CoreFoundation                  0x0000000185b3922c __CFRunLoopDoObservers + 356 (CFRunLoop.c:1718)
8   CoreFoundation                  0x0000000185b3960c __CFRunLoopRun + 832 (CFRunLoop.c:2548)
9   CoreFoundation                  0x0000000185a652d0 CFRunLoopRunSpecific + 392 (CFRunLoop.c:2795)
10  GraphicsServices                0x000000018f27b6f8 GSEventRunModal + 164 (GSEvent.c:2245)
11  UIKit                           0x000000018a62afa8 UIApplicationMain + 1484 (UIApplication.m:3039)
12  MyPictures                  0x0000000100091acc main + 152 (AppDelegate.swift:12)
13  libdyld.dylib                   0x0000000197a26a04 start + 0 (start_glue.s:78)

1 个答案:

答案 0 :(得分:1)

似乎图像为nil会导致崩溃,因此您应该像这样更新代码:

def destroy
  if logged_in?
    forget(current_user)
    log_out
  end
  redirect_to home_path
end