2017-02-27 11 views
5

के साथ कस्टम तालिका दृश्य पाद लेख सेट करें मैं अपने टेबल व्यू में एक कस्टम पाद लेख सेट करने का प्रयास कर रहा हूं। मैंने एक निब फ़ाइल पर पाद लेख बनाया और इसके लिए एक नियंत्रित बनाया।स्विफ्ट

class LoginTableFooter: UITableViewHeaderFooterView 

viewDidLoad() में मैं इस कोड

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

तब मैं viewForFooterInSection

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

    return cell 
} 

viewForFooterInSection लागू नहीं बुलाया गया था लिखा था। मैंने viewForHeaderInSection को लागू करने की भी कोशिश की लेकिन इसे भी नहीं कहा गया। क्या आपको पता है कि क्या गलत है? मेरे टेबल दृश्य में मेरे पास केवल एक अनुभाग है; क्या viewDidLoad पर सीधे पाद लेख सेट करना संभव/बेहतर है?

+0

आप प्रतिनिधि विधि कहा जाता है UITableview का? – iParesh

+0

[UITableViewDelegate विधियों का संभावित डुप्लिकेट स्विफ्ट 3.0 और एक्सकोड 8 माइग्रेशन के बाद नहीं कहा जाता है] (http://stackoverflow.com/questions/40069943/uitableviewdelegate-methods-not-called-after-swift-3-0-and-xcode- 8-माइग्रेशन) – Rob

उत्तर

6

कॉल करने की आवश्यकता को लागू करें - अपने tableview के लिए & डेटा स्रोत प्रतिनिधि और सेट दोनों - 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

स्विफ्ट 3 सीधे का उपयोग> 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

// सबसे पहले आप प्रतिनिधि और तालिका दृश्य का डेटा स्रोत कॉल करने के लिए की जरूरत है। अर्थात्:

tableView.delegate = self 
    tableView.dataSource = self 

// आप इस प्रतिनिधि

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