第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

如何從UITableViewCell獲取UITableView?

如何從UITableViewCell獲取UITableView?

斯蒂芬大帝 2019-11-12 12:51:11
我有一個(gè)UITableViewCell鏈接到對(duì)象的對(duì)象,我需要確定單元格是否可見。從我完成的研究中,這意味著我需要以某種方式訪問(wèn)UITableView包含它的對(duì)象(從那里,有幾種方法可以檢查它是否可見)。所以我想知道是否UITableViewCell有指向的指針UITableView,或者是否還有其他方法可以從單元格獲取指針?
查看完整描述

3 回答

?
月關(guān)寶盒

TA貢獻(xiàn)1772條經(jīng)驗(yàn) 獲得超5個(gè)贊

避免檢查iOS版本


id view = [tableViewCellInstance superview];


while (view && [view isKindOfClass:[UITableView class]] == NO) {

    view = [view superview]; 

}


    UITableView *tableView = (UITableView *)view;


查看完整回答
反對(duì) 回復(fù) 2019-11-12
?
暮色呼如

TA貢獻(xiàn)1853條經(jīng)驗(yàn) 獲得超9個(gè)贊

在iOS7 beta 5中UITableViewWrapperView是的超級(jí)視圖UITableViewCell。也是UITableView一個(gè)的監(jiān)督UITableViewWrapperView。


因此,對(duì)于iOS 7,解決方案是



UITableView *tableView = (UITableView *)cell.superview.superview;


因此,對(duì)于iOS 6以下的iOS,解決方案是



UITableView *tableView = (UITableView *)cell.superview;


查看完整回答
反對(duì) 回復(fù) 2019-11-12
?
收到一只叮咚

TA貢獻(xiàn)1821條經(jīng)驗(yàn) 獲得超5個(gè)贊

Swift 5擴(kuò)展

遞歸地

extension UIView {

    func parentView<T: UIView>(of type: T.Type) -> T? {

        guard let view = superview else {

            return nil

        } 

        return (view as? T) ?? view.parentView(of: T.self)

    }

}


extension UITableViewCell {

    var tableView: UITableView? {

        return parentView(of: UITableView.self)

    }

}

使用循環(huán)

extension UITableViewCell {

    var tableView: UITableView? {

        var view = superview

        while let v = view, v.isKind(of: UITableView.self) == false {

            view = v.superview

        }

        return view as? UITableView

    }

}


查看完整回答
反對(duì) 回復(fù) 2019-11-12
  • 3 回答
  • 0 關(guān)注
  • 1469 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)