[英]Swift - Expand tableview without Storyboard segue
I am trying to create a similar tableview like the one below: 我正在尝试创建类似下面的表格视图:
https://github.com/justinmfischer/SwiftyExpandingCells https://github.com/justinmfischer/SwiftyExpandingCells
I already have a complete tableview with contents, including a filtering system. 我已经有了包含内容的完整表格视图,包括过滤系统。 The current problem is that I want to implement the same functionality to expand cells and show detailed information, without using storyboard .
当前的问题是我想实现相同的功能来扩展单元格并显示详细信息, 而无需使用Storyboard 。
The sample code (link) uses a storyboard segue, but I want to get rid of that so that it can basically do the same thing through code. 示例代码(链接)使用情节提要segue,但是我想摆脱它,以便它基本上可以通过代码完成相同的事情。 I removed the label for the background.
我删除了背景标签。 Just want to get the title and a new controller first by clicking a tableview cell.
只想先通过单击一个表格视图单元格来获得标题和一个新的控制器。
DetailViewController 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
}
}
}
This part needs to change 这部分需要改变
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.