繁体   English   中英

UITable,如何在Swift IOS中为UITable分配委托

[英]UITable, How to assign a delegates to UITable In Swift IOS

我有一个UITable链接到我的viewController ,它具有DataSourceDelegate扩展名。 但是,当我查看视图控制器上的连接时,它们未链接,并且无法弄清楚如何链接它们,对您有所帮助。

IB插座

 @IBOutlet weak var locationTableView: UITableView!

当前代码扩展findCacheViewController:UITableViewDataSource {

//Number Of Rows (Return Value)
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return cacheData.count
}

//Table Content
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = locationTableView.dequeueReusableCellWithIdentifier("Cell")
    let cellData = cacheData[indexPath.row]
    let titleLabelCell = cell?.viewWithTag(1) as! UILabel
    let typeLabelCell = cell?.viewWithTag(2) as! UILabel
    let distanceLabelCell = cell?.viewWithTag(3) as! UILabel

    if userCurrentLocation == nil {
        titleLabelCell.text = "Location Required"
        typeLabelCell.text = ""
        distanceLabelCell.text = ""
    } else {
        titleLabelCell.text = "\(cellData.memoryTitle)"
        typeLabelCell.text = "\(cellData.memoryType)"
    }

    return cell!
}

}

扩展名findCacheViewController:UITableViewDelegate {

//Row Height Based On Condition
//func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
    //let cellData = cachedata[indexPath.row]

    //if conditions {

    //}
//}

//Selected Cell Segue Function
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    selectedCell = cacheData[indexPath.row]
    //performSegueWithIdentifier(<#T##identifier: String##String#>, sender: self)
}

}

我不明白您粘贴的代码有什么意义,您说故事板中的连接有问题吗? 还是您使用代码创建了uitableview,如果是的话,如何设置委托?

无论如何,您都需要ctrl并从uitableview的委托连接中left click drag到情节提要/ xib中正确的uiviewcontroller。 或者,您需要通过代码设置委托。

连接本身不会发生,您需要执行前面提到的两种方法之一。

在情节提要中将委托设置为ViewController的示例

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM