1
當我切換到我的應用程序上的「朋友」選項卡時,出現黑屏問題。這確實發生是因爲我的friendsviewcontroller。我知道這一點,因爲我刪除了viewcontroller的鏈接,它給我提供了正常的屏幕。希望有人可以看到我做了什麼錯選中標籤欄時出現黑屏
FriendsViewController:
import UIKit
import FBSDKLoginKit
class FriendsViewController: UITabBarController, UITableViewDelegate,UITableViewDataSource{
@IBOutlet weak var tableView: UITableView!
@IBOutlet weak var friendTypeSwitch: UISegmentedControl!
@IBOutlet weak var friendSearchBar: UITextField!
var user:User = User()
override func viewDidLoad() {
super.viewDidLoad()
print("Friends tab")
// Do any additional setup after loading the view.
}
override func viewDidAppear(_ animated: Bool) {
print("view did appear")
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 30
}
//What to do with tableview
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = self.tableView.dequeueReusableCell(withIdentifier: "friendCell", for: indexPath) as! friendsCustomCell
user.username = "kulgut123"
cell.friendName.text = user.username
return cell
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return UITableViewAutomaticDimension
}
func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
return UITableViewAutomaticDimension
}
}
class friendsCustomCell: UITableViewCell{
@IBOutlet weak var friendImg: UIImageView!
@IBOutlet weak var friendName: UILabel!
}
您能提供關於您的'FriendsViewController'連接到相應選項卡的方式的信息嗎? – nshuman
我認爲這個問題是因爲你從'UITabBarController'子類。我想你想從'UIViewController'中繼承子類 – ronatory
是的,我已經通過ctrl將標籤欄控制器中的黃色方塊拖動到friendsView,將它連接起來。有沒有更好的方法來實現它? – Pr0tonion