Ребята, запутался.Как в TableView HeaderView сделать заголовком файл xib?


#1

Мужики выручите.Сделай tableViewCell файл xib. Все задал заработало.Поместил Header в сторибораде, потом добавил имя и изображение отобразилось.Создал класс и указал UITableViewHeaderFooterView выкидывает.Пишет что для изображения отсутсвует класс.Я указывал, в итоге автоматом выкидывает.Решил пойти другим методом создал TableViewCell xib. Указал там наследие от UITableViewHeaderFooterView. Добавил все как положено. Сделал функцию указал хедеру ширину.И в функции выдает ошибку выкидывает.Подскажите как правильно сделать HeaderView xib. Уже все уроки пересмотрел и перепробовал. У меня это детальная сцена, и HeaderView типа заголовок, будет содержать изображение и два текста . Будет меняться.Очень буду благодарен за помощь.Вот мой код.

import UIKit
import Parse

class DetailSoccerTableViewController: UIViewController,UITableViewDelegate,UITableViewDataSource,UIScrollViewDelegate  {


    @IBOutlet weak var tableView: UITableView!



    var detailSoccer: Soccer!

    var selectedSoccer = [Soccer]()


    override func viewDidLoad() {
        super.viewDidLoad()


        self.navigationController!.navigationBar.setBackgroundImage(UIImage(), for: UIBarMetrics.default)
        self.navigationController?.navigationBar.shadowImage = UIImage()
        self.navigationController?.navigationBar.isTranslucent = true
        self.navigationController!.view.backgroundColor = UIColor.clear
        self.navigationController?.navigationBar.backgroundColor = UIColor.clear

        title = detailSoccer.detailTitleS

        let nib: UINib = UINib(nibName: "CustomSoccerHeaderView", bundle: nil)
        tableView.register(nib, forCellReuseIdentifier: "CustomSoccerHeaderView")
        tableView.tableFooterView = UIView(frame: .zero)
        tableView.sectionHeaderHeight = 350
        tableView.estimatedRowHeight = 288
        tableView.rowHeight = UITableViewAutomaticDimension
        tableView.separatorStyle = .none
        tableView.delegate = self
        tableView.dataSource = self
        tableView.register(UINib(nibName:"SoccerTableViewCell",bundle:nil), forCellReuseIdentifier: "soccerCell")

        tableView.reloadData()
        loadMatchSoccer()
           //Headerc

        // Do any additional setup after loading the view.
    }

    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)



    }



    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
        return 300
    }
    func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
        let header: CustomSoccerHeaderView = tableView.dequeueReusableHeaderFooterView(withIdentifier: "CustomSoccerHeaderView") as! CustomSoccerHeaderView
        header.nameHeader.text = detailSoccer.detailTitleS
        return header
    }



    func numberOfSections(in tableView: UITableView) -> Int {
        return 1
    }


    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

        return 2
    }




    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let soccerCell = tableView.dequeueReusableCell(withIdentifier: "soccerCell") as! SoccerTableViewCell

        switch indexPath.row {
        case 0:
            soccerCell.titlePrognoz.text = "Аналитика и обзор матча:"
            soccerCell.textSoccer.text = detailSoccer.textSoccer
        case 1:
            soccerCell.titlePrognoz.text = "Прогноз на матч:"
            soccerCell.textSoccer.text = detailSoccer.detailPrognozS
        default:
            break
        }



     return soccerCell


    }






    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return UITableViewAutomaticDimension
    }

    func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
        return UITableViewAutomaticDimension
    }






func loadMatchSoccer() {

    let query = Soccer.query() as! PFQuery<Soccer>
    query.whereKey("detailTitleS", equalTo: detailSoccer.detailTitleS)
    query.findObjectsInBackground  { (objects, error) in
        if error == nil {

            self.selectedSoccer = objects!

            DispatchQueue.main.async(execute: {
                self.tableView.reloadData()
            })

        } else {
            print(error!)
        }
    }
}
}

#2

не совсем по теме. а зачем вообще нужны xib, что они дают? не проще делать все в сториборде или в коде?