gpt4 book ai didi

ios - swift prepareForSegue 不工作/exc_breakpoint(代码=exc_i386_bpt 子代码=0x0)

转载 作者:行者123 更新时间:2023-11-28 07:13:06 25 4
gpt4 key购买 nike

我有一个根本没有被调用的函数。我什至没有打印 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)。我想知道这是什么原因造成的?

最佳答案

您的 ChatRoomViewController 是否在导航 Controller 中?如果是,那么 segue.destinationViewController 不会指向 ChatRoom Controller ?只是一个猜测。在这种情况下,您需要类似的东西:

if segue.identifier == "ToChatRoom" {
let navigationController = segue.destinationViewController as UINavigationController
let chatView = navigationController.viewControllers[0] as ChatRoomViewController
var index = ...

当 performSegueWithIdentifier 行被注释掉时,prepareForSegue 永远不会被调用。从 Storyboard 中显式实例化的下一行绕过了对它的需要。

关于ios - swift prepareForSegue 不工作/exc_breakpoint(代码=exc_i386_bpt 子代码=0x0),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27613637/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com