我有3个视图控制器(拨号器,音频和呼叫视图控制器),拨号器和音频只有它连接到布局并通过音频视图调用它的呼叫,当我在拨号器视图控制器中点击callButton时我必须传递值CallViewController然后直接调用具有StoryBoardID(AudioViewController)的AudioViewController,但我不知道这行返回null,所以我无法移动到AudioViewController。
callViewController = storyboard?.instantiateViewControllerWithIdentifier("AudioCallViewController") as! AudioCallViewController
完整代码:
拨号器视图:
class DialerViewController: UIViewController,UITextFieldDelegate {
@IBOutlet weak var progNameLabel: UILabel!
@IBOutlet weak var progNumberLabel: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
NSNotificationCenter.defaultCenter().addObserver(self, selector: "onConnectionStatusNotification:", name: NOTIFICATION_PHONE_EVENT, object: nil)
}
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
navigationController?.setNavigationBarHidden(true, animated: false)
UIDevice.currentDevice().proximityMonitoringEnabled = false
}
@IBAction func makeCallButton(sender: AnyObject) {
let ownNumber = AppDelegate.sharedInstance().phone?.config().regUser
if !ownNumber!.isEmpty || progNumberLabel.text != ownNumber {
var callViewController: CallViewController?
callViewController = storyboard?.instantiateViewControllerWithIdentifier("AudioCallViewController") as! AudioCallViewController //Exception in this line
callViewController?.number = progNumberLabel.text
//self.presentedViewController(callViewController, animated:true, completion:nil)
navigationController?.pushViewController(callViewController!, animated: true)
}
}
func onConnectionStatusNotification(notification: NSNotification) {
let status = PhoneEvents(rawValue: notification.object!.integerValue)
let _ = status! == .RegSuccess
}
deinit {
NSNotificationCenter.defaultCenter().removeObserver(self)
}
}
CallView:
class CallViewController: UIViewController, UITextFieldDelegate {
var number: String?
var callId: Int?
var incoming: Bool?
override func viewDidLoad() {
super.viewDidLoad()
print("The Number is" + number!)
NSNotificationCenter.defaultCenter().addObserver(self, selector: "onConnectionStatusNotification:", name: NOTIFICATION_PHONE_EVENT, object: nil)
}
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
navigationController?.setNavigationBarHidden(true, animated: false)
NSNotificationCenter.defaultCenter().addObserver(self, selector: "onCallNotification:", name: NOTIFICATION_CALL_EVENT, object: nil)
}
func closeView() {
if self == navigationController?.topViewController {
navigationController?.popViewControllerAnimated(true)
}
}
func onCallNotification(notification: NSNotification) {
}
func onConnectionStatusNotification(notification: NSNotification) {
}
deinit {
NSNotificationCenter.defaultCenter().removeObserver(self)
}
}
AudioViewController:
class AudioCallViewController: CallViewController {
.............
}
答案 0 :(得分:0)
NULL
在上面,你没有声明callViewController = storyboard?.instantiateViewControllerWithIdentifier("AudioCallViewController") as! AudioCallViewController //Exception in this line
是什么,所以肯定会返回null
默认情况下,您的故事板应为storyboard
,因此请在该声明上方添加此代码
Main