Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift:Picker在以编程方式显示其视图控制器时抛出错误_Swift_Xcode_Swift3 - Fatal编程技术网

Swift:Picker在以编程方式显示其视图控制器时抛出错误

Swift:Picker在以编程方式显示其视图控制器时抛出错误,swift,xcode,swift3,Swift,Xcode,Swift3,当我通过方法present(viewController(),animated:true,completion:nil)呈现包含选择器的视图控制器时,在展开可选值时抛出错误意外发现nil。有人能告诉我怎么解决这个问题吗 回溯: * thread #1: tid = 0x848b34, 0x000000010eb3bc50 libswiftCore.dylib`function signature specialization <preserving fragile attribute, A

当我通过方法
present(viewController(),animated:true,completion:nil)
呈现包含选择器的视图控制器时,在展开可选值时抛出错误
意外发现nil。有人能告诉我怎么解决这个问题吗

回溯:

* 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
目标(
createNew()

这应该是所有与问题相关的代码。如果需要的话,我可以发布更多的东西,但正如我前面所说的,这适用于故事板片段,并且由于某些原因,在以编程方式呈现时不起作用

这适用于故事板分段

是的,因为当你做一个序列时,你正在使用故事板中的视图控制器,其中有一个视图,该视图包含一个选择器视图,所有的插座都连接起来

但是您的
createNew
会创建一个不同的视图控制器,一个具有空视图的控制器,其中不包含选择器视图或任何其他内容。所以你的插座从来没有连接,它们是零,你崩溃


您需要执行segue所做的操作:从情节提要中拉出视图控制器。

您需要提供更多详细信息、崩溃日志吗?一些代码等,很难帮助您仅猜测发生了什么提供了一个回溯viewContoller()是问题的症结何在?我不太清楚确切的原因是什么。用表演而不是礼物…它会解决你的问题
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)
}
@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()
}