繁体   English   中英

Swift-在没有Storyboard Segue的情况下展开表格视图

[英]Swift - Expand tableview without Storyboard segue

我正在尝试创建类似下面的表格视图:

https://github.com/justinmfischer/SwiftyExpandingCells

我已经有了包含内容的完整表格视图,包括过滤系统。 当前的问题是我想实现相同的功能来扩展单元格并显示详细信息, 而无需使用Storyboard

示例代码(链接)使用情节提要segue,但是我想摆脱它,以便它基本上可以通过代码完成相同的事情。 我删除了背景标签。 只想先通过单击一个表格视图单元格来获得标题和一个新的控制器。

DetailViewController

class DetailVC: UIViewController {

var brand: Brand?

override func viewDidLoad() {
    super.viewDidLoad()

    self.setup()
}

func setup() {
    self.view.frame.origin.y = UIApplication.sharedApplication().statusBarFrame.size.height

    if let brand = self.brand {
        self.title = brand.name
    }
}
}

这部分需要改变

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    self.selectedCellFrame = tableView.convertRect(tableView.cellForRowAtIndexPath(indexPath)!.frame, toView: tableView.superview)
    self.selectedBrand = BrandManager.sharedInstance.brands[indexPath.row]

    self.performSegueWithIdentifier(.DetailVC , sender: nil)
}

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    switch segueIdentifierForSegue(segue) {
        case .DetailVC:
            let vc = segue.destinationViewController as! DetailVC
                vc.brand = self.selectedBrand

            self.navigationController?.delegate = self
    }
}
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
        self.selectedCellFrame = tableView.convertRect(tableView.cellForRowAtIndexPath(indexPath)!.frame, toView: tableView.superview)
        self.selectedBrand =  BrandManager.sharedInstance.brands[indexPath.row]

        let vc = storyboard?.instantiateViewControllerWithIdentifier("DetailVc") as! DetailVC
        vc.brand = self.selectedBrand
        self.navigationController?.pushViewController(vc, animated: true)
     }//// add the storyboardID for the detailsVc as "DetailVc"

暂无
暂无

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

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