Swift

2017-02-27 17 views
5

ile özel bir tablo görünümü altbilgisi ayarlama Tablo görünümüne özel altbilgi oluşturmaya çalışıyorum. Altbilgiyi bir nib dosyası üzerinde oluşturdum ve bunun için kontrollü bir şekilde oluşturdum.Swift

class LoginTableFooter: UITableViewHeaderFooterView 

viewDidLoad() ben hiç çağrılmadı

let footerNib = UINib(nibName: "LoginTableFooter", bundle: nil) 
     tableView.register(footerNib, forHeaderFooterViewReuseIdentifier: "LoginTableFooter") 

Sonra

func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? { 
    let cell = self.tableView.dequeueReusableHeaderFooterView(withIdentifier: "LoginTableFooter") 
    let header = cell as! LoginTableFooter 

    return cell 
} 

viewForFooterInSectionviewForFooterInSection uygulanan bu kodu yazdım. Ayrıca viewForHeaderInSection'u uygulamayı denedim ama aynı zamanda çağrılmadı. Neyin yanlış olduğuna dair bir fikrin var mı? Tablo görünümünde yalnızca bir bölüm var; altbilgiyi doğrudan viewDidLoad üzerinden ayarlamak mümkün mü? Swift 3

+0

Eğer temsilci yöntemi denir mı UITableview? – iParesh

+0

[3.0 ve Xcode 8 geçişinden sonra çağrılmayan UITableViewDelegate yöntemlerinin] olası kopyası (http://stackoverflow.com/questions/40069943/uitableviewdelegate-methods-not-called-after-swift-3-0-and-xcode- 8-taşıma) – Rob

cevap

6

çağırmanız gerekir Uygulamak - senin tableview için & veri kaynağı temsilci ve her iki set - heightForFooterInSection & viewForFooterInSection

tableView.delegate = self 
tableView.dataSource = self 

// set view for footer 
func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? { 
    let footerView = UIView(frame: CGRect(x: 0, y: 0, width: tableView.frame.size.width, height: 40)) 
    footerView.backgroundColor = UIColor.blue 
    return footerView 
} 

// set height for footer 
func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat { 
    return 40 
} 
0

Doğrudan kullanmak> viewForFooterInSection

override func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? { 
    let footerView = UIView(frame: CGRect(x: 0, y: 0, width: tableView.frame.size.width, height: 40)) 
    footerView.backgroundColor = UIColor.red 

    return footerView 
    } 
0

// öncelikle tablo görünümünün temsilci ve veri kaynağı aramak gerekiyor. yani:

tableView.delegate = self 
    tableView.dataSource = self 

// bunu Temsilciye

 func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat { 
     return "your expected footer height" 
}