【发布时间】:2016-08-22 09:50:13
【问题描述】:
我有一个HomePageTableViewController,其中包含三个自定义的TableViewCell,每个TableViewCell 都包含一个UICollectionView。当用户点击每个TableViewCell 并转到不同的ViewController 以显示CollectionView 的详细信息时,我想执行segue。我使用了这段代码:
import UIKit
class HomePageTableViewController: UITableViewController, PostDelegate {
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 3
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 1
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
if indexPath.section == 0 {
let cell = tableView.dequeueReusableCellWithIdentifier("TableViewCell1") as! HomePageTableViewCell1
cell.getCategory()
// cell.scrollToNextCell()
// cell.startTimer()
cell.postDelegate = self
tableView.rowHeight = 260
return cell
}
else if indexPath.section == 1 {
let cell = tableView.dequeueReusableCellWithIdentifier("TableViewCell2") as! HomePageTableViewCell2
cell.getCategory()
tableView.rowHeight = 140
return cell
}
else {
let cell = tableView.dequeueReusableCellWithIdentifier("TableViewCell3") as! HomePageTableViewCell3
cell.getCategory()
tableView.rowHeight = 470
return cell
}
}
func selectedPost(post: Posts) {
//You will get your post object here, do what you want now
self.performSegueWithIdentifier("goToDetail", sender: post)
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
let post = sender as! Posts
let postDetailPage = segue.destinationViewController as? DetailTableViewController
postDetailPage!.passPost = post
}
无论我点击TableViewCell,这段代码都会完成这项工作,它会进入带有标识符“goToDetail”的相同segue。例如,对于HomeTableTableViewCell2,我想使用标识符“goToDetail2”等执行segue。我怎样才能做到这一点?
【问题讨论】:
标签: ios swift uitableview segue