Ios 选择选项卡栏时出现黑屏
当我切换到应用程序上的“朋友”选项卡时,我遇到了黑屏问题。这是因为我的朋友ViewController。我知道这一点,因为我删除了指向viewcontroller的链接,它向我显示了正常的屏幕。希望有人能看到我做错了什么 FriendsViewController:Ios 选择选项卡栏时出现黑屏,ios,swift,viewcontroller,Ios,Swift,Viewcontroller,当我切换到应用程序上的“朋友”选项卡时,我遇到了黑屏问题。这是因为我的朋友ViewController。我知道这一点,因为我删除了指向viewcontroller的链接,它向我显示了正常的屏幕。希望有人能看到我做错了什么 FriendsViewController: import UIKit import FBSDKLoginKit class FriendsViewController: UITabBarController, UITableViewDelegate,UITableView
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!
}
正如ronatory所建议的,您应该从UIViewController而不是UIAbbarController中为FriendsViewController创建子类
class FriendsViewController: UIViewController, UITableViewDelegate,UITableViewDataSource {
//type your code here
}
您能否提供有关如何将
FriendsViewController
连接到相应选项卡的信息?我认为问题在于您从UITabBarController
中创建了子类。我想您想从UIViewController
中创建子类,是的,我已经通过ctrl键将它从选项卡栏控制器中的黄色方块直接拖动到friendsView来连接它。有没有更好的方法来实现它?你是对的@ronatoryNice,所以它现在可以工作了?