线程 1: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0) Swift
Posted
技术标签:
【中文标题】线程 1: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0) Swift【英文标题】:Thread 1: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0) Swift 【发布时间】:2018-06-01 07:50:41 【问题描述】:我正在尝试从一种视图切换到另一种视图,但出现此错误,我不知道为什么会出现此错误。
我用这个函数去下一个控制器:
func showChatControllerForGroup(_ user: [User], groupName: String)
let vc: GroupChatMessangingViewController = self.storyboard?.instantiateViewController(withIdentifier: "GroupChatMessangingViewController") as! GroupChatMessangingViewController
//it crashed above here
vc.group?.members = user
vc.group?.name = groupName
self.navigationController?.pushViewController(vc, animated: true)
要调用它,我在另一个视图中调用它:
var group: Group?
didSet
navigationItem.title = group?.name
var chosenUser: [User] = []
let user = self.chosenUser
override func viewDidLoad()
super.viewDidLoad()
navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Create", style: .plain, target: self, action: #selector(createGroup))
// Do any additional setup after loading the view.
@objc func createGroup()
let transition = CATransition()
transition.duration = 0.5
transition.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
transition.type = kCATransitionReveal
transition.subtype = kCATransitionFromBottom
navigationController?.view.layer.add(transition, forKey: nil)
_ = navigationController?.popViewController(animated: true)
let user = self.chosenUser
self.nextVC.showChatControllerForGroup(user, groupName: groupNameTextField.text!)
以防万一有人需要查看我的用户类:
class User
var id: String?
var name: String?
var email: String?
var profileImageUrl: String?
var lastMessage: String?
var timestamp: String? //reason why this exist was because in mainmenu, we appended users, not msssage
init()
init(dictionary: [String: AnyObject])
self.id = dictionary["id"] as? String
self.name = dictionary["name"] as? String
self.email = dictionary["email"] as? String
self.profileImageUrl = dictionary["profileImageUrl"] as? String
在我的小组课上:
class Group
var id: String?
var name: String?
var members: [User]!
var groupImageUrl: String?
var lastMessage: String?
var timestamp: String?
init()
init(dictionary: [String: AnyObject])
self.id = dictionary["id"] as? String
self.name = dictionary["name"] as? String
有什么原因导致它崩溃吗?
【问题讨论】:
在 Group 类上尝试从 var members 更改成员:[User]!到 var 成员:[User] = [] 完成,仍然在同一个地方崩溃 好的,然后在 showChatControllerForGroup 上尝试使用它所拥有的故事板名称再次初始化故事板,而不是使用 self.storyboard 调用 GroupChatMessangingViewController?但有了新变量 【参考方案1】:我猜你在
let vc: GroupChatMessangingViewController = self.storyboard?.instantiateViewController(withIdentifier: "GroupChatMessangingViewController") as! GroupChatMessangingViewController
您调用了错误的故事板。检查并查看您是否在正确的情节提要中。
【讨论】:
好的,知道了!谢谢。我只是想知道我只有一个故事板,为什么不是自我。是正确的......但无论如何 添加了 let storyboard = UIStoryboard(name: "Main", bundle: nil)以上是关于线程 1: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0) Swift的主要内容,如果未能解决你的问题,请参考以下文章
Swift,线程 1:EXC_BAD_INSTRUCTION 错误
错误“线程 1:EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)”是啥意思?
线程 1:EXC_BAD_INSTRUCTION(code=EXC_I386_INVOP,subcode=0*0) 错误
线程 1:EXC_BAD_INSTRUCTION(代码=EXC_1386_INVOP,子代码=0x0)