简体   繁体   English

segue时如何获取自定义细胞标签?

[英]How to get custom cell label when segue?

I'm trying to get the name of the selected row in the custom cell. 我正在尝试获取自定义单元格中所选行的名称。 How I can do that in Swift? 我该如何在Swift中做到这一点?

    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {

    var selectedCell = CustomCell()
    selectedCell = tableView(tbl, cellForRowAtIndexPath: <#NSIndexPath#>)

    if(segue.identifier == "next") {
        var next = (segue.destinationViewController as! EngineViewController)
        next.titleSub = selectedCell.cell.lblBrand.text
    }
}

I believe if you are just selecting a cell, the cell should be the sender. 我相信,如果您只是选择一个单元,则该单元应该是发送者。 Try this 尝试这个

if let selectedCell = sender as? CustomCell {
    if(segue.identifier == "next") {
    var next = (segue.destinationViewController as! EngineViewController)
    next.titleSub = selectedCell.cell.lblBrand.text
    }
}

You could attempt to override didSelectRowAtIndexPath to get your cell. 您可以尝试覆盖didSelectRowAtIndexPath来获取单元格。

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let cell = tableView.dequeueReusableCellWithIdentifier("CellIdentifier", forIndexPath: indexPath) as! CustomCell
    cell.yourLabel.textYouWant
let yourViewController = storyboard?.instantiateViewControllerWithIdentifier("ViewController") as! ViewController
    navigationController?.pushViewController(yourViewController, animated: true)

} }

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

相关问题 Swift - 如何在按下不同自定义单元格中的按钮时获取自定义单元格标签的值? - Swift - How to get the value of a custom cell label when pressing a button in a different custom cell? 如何在UICollectionView中单击自定义单元格时触发segue - How can I trigger a segue when clicking a custom cell in a UICollectionView 如何在 TableView 单元格中按住按钮时进行 segue - How to segue when a button is held in a TableView cell 如何获取UITableView标签文本字符串-自定义单元格 - How to get UITableView Label Text string - Custom Cell 当点击自定义TableView单元格中的UITextField时,选择到新视图 - Segue to new view when UITextField within Custom TableView Cell tapped 自定义UITableViewController单元格序列不推送 - custom UITableViewController cell segue not pushing 填充UITableViewController时,自定义单元格中的标签为null - Label in custom cell is null when populating UITableViewController 快速滚动时,自定义单元格中的多行标签与下一个单元格重叠 - Multiline label in custom cell overlaps the next cell when scrolling fast Swift如何从CollectionView中的准备准备中获取单元格 - Swift how to get cell from prepare for segue in collectionView 如何在segue中获取选定的表格视图单元格行? - How to get selected table view cell row in segue?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM