2

UITableViewカスタマイズされたヘッダーがあります。そのヘッダーには、画像付きのボタンがあります。

 func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {

    let cView = UIView(frame: CGRectMake(0, 0, tableView.frame.size.width, 40))

    itemNumBtn = UIButton(frame: CGRectMake(0, 0, 70, 42))
    itemNumBtn.setBackgroundImage(UIImage(named: "hide.png"), forState: .Normal)
    cView.addSubview(itemNumBtn)

    return cView
}

5 つのヘッダー セクションがあります。

別の関数では、各ボタンの画像を取得する方法、各ボタンにアクセスする必要があります

元:

fun getHeader() {
    // how to access each header and buttons
    var eachBtn = each button in the header
    var image = all the images of all header section
}

前もって感謝します

4

1 に答える 1

4

を取得buttonおよびimage取得するために、次のようheaderにカスタマイズされた for を実装できますUIViewheader

class HeaderView: UIView {
    var button: UIButton
    var image: UIImage

    func init() {
        ...
    }
} 

HeaderViewこれをtableView(tableView: UITableView, viewForHeaderInSection section: Int)コールバックで返します。

func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
    return HeaderView()
}

次にtableView.headerViewForSection(section:)、5 つのカスタマイズされたヘッダー ビューを取得するために使用します。

func getHeaders() {

    for index in 1...5 {
         let header = tableView.headerViewForSection(section: index) as! HeaderView
         let button = header.button
         let image = header.image
    }
}
于 2015-10-08T05:41:05.953 に答える