2017-08-14 34 views
-1

當我提出其具有通過該方法在present(viewController(), animated: true, completion: nil)它拾取器的視圖控制器選取器拋出錯誤,該錯誤unexpectedly found nil while unwrapping an Optional value被拋出。有人能告訴我如何解決這個問題嗎?夫特:當它的視圖控制器被呈現編程

回溯:

* thread #1: tid = 0x848b34, 0x000000010eb3bc50 libswiftCore.dylib`function signature specialization <preserving fragile attribute, Arg[2] = Dead, Arg[3] = Dead> of Swift._fatalErrorMessage (Swift.StaticString, Swift.StaticString, Swift.StaticString, Swift.UInt, flags : Swift.UInt32) -> Swift.Never + 96, queue = 'com.apple.main-thread', stop reason = EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0) 
frame #0: 0x000000010eb3bc50 libswiftCore.dylib`function signature specialization <preserving fragile attribute, Arg[2] = Dead, Arg[3] = Dead> of Swift._fatalErrorMessage (Swift.StaticString, Swift.StaticString, Swift.StaticString, Swift.UInt, flags : Swift.UInt32) -> Swift.Never + 96 
* frame #1: 0x000000010c19c231 Exercise Generator`createNew.viewDidLoad(self=0x00007f9d12d69b30) ->() + 177 at createNew.swift:43 
frame #2: 0x000000010c19c722 Exercise Generator`@objc createNew.viewDidLoad() ->() + 34 at createNew.swift:0 
frame #3: 0x000000010d32ea3d UIKit`-[UIViewController loadViewIfRequired] + 1258 
frame #4: 0x000000010d32ee70 UIKit`-[UIViewController view] + 27 
frame #5: 0x000000010dbef6a4 UIKit`-[_UIFullscreenPresentationController _setPresentedViewController:] + 87 
frame #6: 0x000000010d309702 UIKit`-[UIPresentationController initWithPresentedViewController:presentingViewController:] + 141 
frame #7: 0x000000010d341e97 UIKit`-[UIViewController _presentViewController:withAnimationController:completion:] + 3956 
frame #8: 0x000000010d34526b UIKit`-[UIViewController _performCoordinatedPresentOrDismiss:animated:] + 530 
frame #9: 0x000000010d344d51 UIKit`-[UIViewController presentViewController:animated:completion:] + 179 
frame #10: 0x000000010c1b18fa Exercise Generator`openRecent.myaction(sender=0x00007f9d12c45f50, self=0x00007f9d12c451e0) ->() + 1706 at openRecent.swift:57 
frame #11: 0x000000010c1b1afa Exercise Generator`@objc openRecent.myaction(sender : UIButton!) ->() + 58 at openRecent.swift:0 
frame #12: 0x000000010d18e8bc UIKit`-[UIApplication sendAction:to:from:forEvent:] + 83 
frame #13: 0x000000010d314c38 UIKit`-[UIControl sendAction:to:forEvent:] + 67 
frame #14: 0x000000010d314f51 UIKit`-[UIControl _sendActionsForEvents:withEvent:] + 444 
frame #15: 0x000000010d313e4d UIKit`-[UIControl touchesEnded:withEvent:] + 668 
frame #16: 0x000000010d6be304 UIKit`_UIGestureEnvironmentSortAndSendDelayedTouches + 5645 
frame #17: 0x000000010d6b8fcb UIKit`_UIGestureEnvironmentUpdate + 1472 
frame #18: 0x000000010d6b89c3 UIKit`-[UIGestureEnvironment _deliverEvent:toGestureRecognizers:usingBlock:] + 521 
frame #19: 0x000000010d6b7ba6 UIKit`-[UIGestureEnvironment _updateGesturesForEvent:window:] + 286 
frame #20: 0x000000010d1fdc1d UIKit`-[UIWindow sendEvent:] + 3989 
frame #21: 0x000000010d1aa9ab UIKit`-[UIApplication sendEvent:] + 371 
frame #22: 0x000000010d99772d UIKit`__dispatchPreprocessedEventFromEventQueue + 3248 
frame #23: 0x000000010d990463 UIKit`__handleEventQueue + 4879 
frame #24: 0x000000010cd0d761 CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17 
frame #25: 0x000000010ccf298c CoreFoundation`__CFRunLoopDoSources0 + 556 
frame #26: 0x000000010ccf1e76 CoreFoundation`__CFRunLoopRun + 918 
frame #27: 0x000000010ccf1884 CoreFoundation`CFRunLoopRunSpecific + 420 
frame #28: 0x00000001113f1a6f GraphicsServices`GSEventRunModal + 161 
frame #29: 0x000000010d18cc68 UIKit`UIApplicationMain + 159 
frame #30: 0x000000010c1af2ef Exercise Generator`main + 111 at AppDelegate.swift:12 
frame #31: 0x000000011046768d libdyld.dylib`start + 1 

相關代碼: 本發明的方法:

func myaction(sender: UIButton!) { //several buttons are created programmatically, all trigger this function 

    print("button pressed") 
    print(sender.currentTitleColor) 
    switch sender.tag { 

    case 0 : 
     print("First Button") 

    case 1 : 
     print("Second Button") 

    default: 
     print("button action from undefined button") 
    } 
    present(createNew(), animated: true, completion: nil) 
} 

目的地(createNew()

@IBOutlet weak var nameField: UITextField!{ 
    didSet { 
     nameField.delegate = self 
    } 
} 
@IBOutlet weak var tagButton: UIButton! 
@IBOutlet var PatientPicker: UIPickerView! 
@IBOutlet var OrientationPicker: UIPickerView! 
@IBOutlet var tagLabel: UILabel! 
@IBOutlet weak var saveButton: UIButton! 

var patientPickerData : [String] = [String]() 
var orientationPickerData: [String] = [String]() 
var exerciseName: String = "Untitled" 
var orientation : String = String() 
var tag: String = "" 

override func viewDidLoad() { 
    super.viewDidLoad() 
    // Do any additional setup after loading the view. 

    //Picker info 
    self.PatientPicker.dataSource = self  //Error happens here 
    self.PatientPicker.delegate = self 
    self.OrientationPicker.dataSource = self 
    self.OrientationPicker.delegate = self 
    patientPickerData = ["--Select Patient--", "No Patient"] 
    orientationPickerData = ["--Select Orientation--","Standing","Reclining"] 
    //End of viewDidLoad() 
} 

這應該是所有與問題相關的代碼。如果需要的話,有一些更多的東西我可以發佈,但正如我前面說的這個作品與故事板塞格斯出於某種原因,編程時呈現不起作用。

+0

您需要提供更多的細節,崩潰日誌?一些代碼等,很難幫助你只猜測發生了什麼 –

+0

提供了一個回溯 –

+1

viewContoller()是問題 – OverD

回答

0

這個作品與故事板塞格斯

是的,因爲當你做你正在使用的故事板,它有一個觀點認爲控制器SEGUE,而且視圖包含一個選擇器視圖和所有網點被吸引了。

但你createNew創建一個不同的視圖控制器,一個用不含選擇器視圖或其他任何一個空的觀點。所以,你的店鋪都沒有釣到了,他們是零,你崩潰。

您需要執行segue的操作:從故事板中拉出視圖控制器

相關問題