我在没有导航栏的viewcontroller中有一个按钮(我真的认为这不重要)。当我点击按钮时,我想要转到另一个视图控制器,但它无法正常工作。我使用以下方法以编程方式将其定位到SecondViewcontroller:
@IBAction func sendMessage(_ sender: Any) {
performSegue(withIdentifier: "chatting", sender: self)
}
我在storyboard中设置了show关系,并将标识符设置为“chat”。我真的很困惑,因为我使用完全相同的设置为另一个视图控制器中的另一个按钮,这是有效的。但是,在这种情况下,我收到错误: “致命错误:在打开可选值时意外发现nil”
这就是我整个FirstViewController的样子:
import UIKit
import Firebase
import FirebaseStorage
import FirebaseAuth
import FBSDKCoreKit
import FBSDKLoginKit
import FirebaseDatabase
class UsersProfileViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
@IBOutlet var Usersname: UILabel!
@IBOutlet var UsersProfilePic: UIImageView!
@IBOutlet var TableView: UITableView!
var username: String?
var userpicuid: String?
var posts = NSMutableArray()
var loggedInUser = FIRAuth.auth()?.currentUser
override func viewDidLoad() {
super.viewDidLoad()
TableView.delegate = self
TableView.dataSource = self
//Making the Facebook profile pic round
self.UsersProfilePic.layer.borderWidth = 2.0
self.UsersProfilePic.layer.borderColor = UIColor.white.cgColor
self.UsersProfilePic.layer.cornerRadius = self.UsersProfilePic.frame.size.width/2
self.UsersProfilePic.clipsToBounds = true
//set the user's pic and name
self.Usersname.text = self.username
if let postProfile = self.userpicuid{
let imageRef = FIRStorage.storage().reference().child((userpicuid)!+"/profile_pic.jpg")
imageRef.data(withMaxSize: 25 * 1024 * 1024, completion: { (data, error) -> Void in
if error == nil {
let image = UIImage(data: data!)
self.UsersProfilePic.image = image
}else {
print("Error downloading image:" )
}})}
}
override func viewWillAppear(_ animated: Bool) {
self.navigationController?.isNavigationBarHidden = true
}
override func viewWillDisappear(_ animated: Bool) {
self.navigationController?.isNavigationBarHidden = false
}
// Properties of the UITableView
func numberOfSections(in tableView: UITableView) -> Int {
// #warning Incomplete implementation, return the number of sections
return 1
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
TableView.separatorStyle = .none
return self.posts.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "UsersCell", for: indexPath) as! UserProfileTableViewCell
//Configure the cell
print(posts[indexPath.row])
let post = self.posts[indexPath.row] as! [String: AnyObject]
cell.Title.text = post["title"] as? String
cell.Author.text = post["Author"] as? String
// cell.ISBN.text = post["ISBN"] as? String
cell.Price.text = post["Price"] as? String
cell.CustomView.layer.cornerRadius = 7
cell.CustomView.layer.masksToBounds = false
cell.CustomView.layer.shadowColor = UIColor.black.withAlphaComponent(0.2).cgColor
cell.CustomView.layer.shadowOffset = CGSize(width: 0, height: 0)
cell.CustomView.layer.shadowOpacity = 0.8
if let imageName = post["image"] as? String {
let imageRef = FIRStorage.storage().reference().child("images/\(imageName)")
imageRef.data(withMaxSize: 25 * 1024 * 1024, completion: { (data, error) -> Void in
if error == nil {
let image = UIImage(data: data!)
cell.Book.image = image
}else {
print("Error downloading image:" )
}})}
return cell
}
///THIS IS THE END OF THE TABLEVIEW PROPERTIES//////
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func sendMessage(_ sender: Any) {
performSegue(withIdentifier: "chatting", sender: self)
}
@IBAction func SwipeBack(_ sender: UISwipeGestureRecognizer) {
}
}
这是我的控制台日志:
**2017-05-16 13:35:11.462713-0400 Lit_Swap[7837:4207118] WARNING: Firebase Analytics App Delegate Proxy is disabled. To log deep link campaigns manually, call the methods in FIRAnalytics+AppDelegate.h.
2017-05-16 13:35:11.467597-0400 Lit_Swap[7837:4207118] Firebase automatic screen reporting is enabled. Call +[FIRAnalytics setScreenName:setScreenClass:] to set the screen name or override the default screen class name. To disable automatic screen reporting, set the flag FirebaseAutomaticScreenReportingEnabled to NO in the Info.plist
2017-05-16 13:35:11.621902-0400 Lit_Swap[7837:4207181] [Firebase/Core][I-COR000001] Configuring the default app.
2017-05-16 13:35:11.622 Lit_Swap[7837] <Debug> [Firebase/Core][I-COR000001] Configuring the default app.
2017-05-16 13:35:11.651567-0400 Lit_Swap[7837:4207186] <FIRAnalytics/INFO> Firebase Analytics v.3600000 started
2017-05-16 13:35:11.652 Lit_Swap[7837:] <FIRAnalytics/INFO> Firebase Analytics v.3600000 started
2017-05-16 13:35:11.654094-0400 Lit_Swap[7837:4207186] <FIRAnalytics/INFO> To enable debug logging set the following application argument: -FIRAnalyticsDebugEnabled
2017-05-16 13:35:11.654 Lit_Swap[7837:] <FIRAnalytics/INFO> To enable debug logging set the following application argument: -FIRAnalyticsDebugEnabled
2017-05-16 13:35:11.810969-0400 Lit_Swap[7837:4207181] <FIRAnalytics/INFO> Firebase Analytics enabled
2017-05-16 13:35:11.811 Lit_Swap[7837:] <FIRAnalytics/INFO> Firebase Analytics enabled
2017-05-16 13:35:12.717443-0400 Lit_Swap[7837:4207118] Could not load the "User Filled-50" image referenced from a nib in the bundle with identifier "com.JesamUsani.Lit-Swap"
2017-05-16 13:35:12.717775-0400 Lit_Swap[7837:4207118] Could not load the "User Filled-50" image referenced from a nib in the bundle with identifier "com.JesamUsani.Lit-Swap"
2017-05-16 13:35:12.728010-0400 Lit_Swap[7837:4207118] Failed to set (clipToBounds) user defined inspected property on (UINavigationItem): [<UINavigationItem 0x1701de000> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key clipToBounds.
2017-05-16 13:35:12.872870-0400 Lit_Swap[7837:4207181] [Firebase/Core][I-COR000019] Clearcut post completed.
2017-05-16 13:35:12.872 Lit_Swap[7837] <Debug> [Firebase/Core][I-COR000019] Clearcut post completed.2017-05-16 13:35:20.147426-0400 Lit_Swap[7837:4207182] [MC] System group container for systemgroup.com.apple.configurationprofiles path is /private/var/containers/Shared/SystemGroup/systemgroup.com.apple.configurationprofiles
2017-05-16 13:35:20.148996-0400 Lit_Swap[7837:4207182] [MC] Reading from public effective user settings.
fatal error: unexpectedly found nil while unwrapping an Optional value
2017-05-16 13:35:22.856791-0400 Lit_Swap[7837:4207118] fatal error: unexpectedly found nil while unwrapping an Optional value**