我正在尝试创建一个类似的表视图如下:
https://github.com/justinmfischer/SwiftyExpandingCells我已经有一个完整的表视图与内容,包括一个过滤系统。当前的问题是,我想实现相同的功能来展开单元格和显示详细信息,,而不使用故事板。
示例代码(link)使用了storyboard segue,但我想去掉它这样它就可以通过代码做同样的事情。我去掉了背景的标签。我想先通过点击tableview单元格获取标题和新控制器。
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"