我有这个功能,根本没有被调用。我没有事件准备印制segue ...
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
println("PREPARING FOR SEGUE");
if (segue.identifier == "ToChatRoom") {
var chatView:ChatRoomViewController = segue.destinationViewController as ChatRoomViewController;
var index = coralReefTableView.indexPathForSelectedRow()!.row;
var id = roomIDArray.objectAtIndex(index);
println("ID IS : \(id)");
chatView.selectedRoomID = id as Int;
}
}
我用这些代码行调用segue ......
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
var cell = tableView.cellForRowAtIndexPath(indexPath);
//performSegueWithIdentifier("ToChatRoom", sender: self);
let nextController:AnyObject! = self.storyboard?.instantiateViewControllerWithIdentifier("chatRoom");
self.showViewController(nextController as UIViewController, sender: nextController);
当我取消注释performSegueWithIdentifier时,我收到此错误:exc_breakpoint(code = exc_i386_bpt subcode = 0x0)。我想知道这会是什么原因?
答案 0 :(得分:1)
您的ChatRoomViewController是否在导航控制器中?如果是,则segue.destinationViewController不会指向ChatRoom控制器?只是一个猜测。在这种情况下,您需要以下内容:
if segue.identifier == "ToChatRoom" {
let navigationController = segue.destinationViewController as UINavigationController
let chatView = navigationController.viewControllers[0] as ChatRoomViewController
var index = ...
当performSegueWithIdentifier行被注释掉时,从不调用prepareForSegue。从故事板中明确实例化的下一行绕过了它的需要。