Im working on a messaging app atm and on the ChatView screen where you can see the thread of messages passed between users, I want to give my users the ability to visit the profile of the user they're communicating with.
To get to the ChatView class, a user selects another user to message from the list users. Once that user is selected, a segue to ChatView is happened where the user is initialized. from that view, the user can select the navigation title that displays the name of the person they're chatting with to view their profile. To pass the user data over to the next view controller, I've done this:
// line inside another function setting up the navigation title
let button = UIButton(type: .custom)
button.frame = CGRect(x: 0, y: 0, width: 100, height: 30)
button.titleLabel?.textColor = .white
button.setTitle(self.otherUser.name, for: .normal)
button.addTarget(self, action: #selector(showUserProfile), for: .touchUpInside)
navigationItem.titleView = button
@objc func showUserProfile() {
let viewUserProfile = ViewProfileViewController()
viewUserProfile.user = self.otherUser
navigationController?.pushViewController(viewUserProfile, animated: true)
}
However, when I try this out, I get this error: (11db) Unexpectedly found nil while implicitly unwrapping an Optional value
, on the Users Profile page, and the app closes. What am I doing wrong here?