所以我试图在表格 View 中使用 3 个不同的部分单元格创建 3 个不同的 segues。我正在获取初始表格 View 以填充自定义单元格数据,但无法将每个单元格设置为转至每个相应的新 ViewController...所以我想要 3 个具有 3 个不同转场的单元格...感谢您的帮助!
class ProfileTableViewController: UITableViewController {
var tableData: [String] = ["milan", "parisTower", "alps_1-blur", "alps_1", "meStanding"]
//register TravelBook Custom Cell
let nib = UINib(nibName: "TravelBookCell", bundle: nil)
tableView.registerNib(nib, forCellReuseIdentifier: "TravelBookCell")
self.tableView.dataSource = self
}
// MARK: - Table view data source
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 3
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if(section == 0) {
return 1
}
if(section == 1) {
return 1
}
else {
return tableData.count
}
}
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
_ = tableView.cellForRowAtIndexPath(indexPath)
tableView.deselectRowAtIndexPath(indexPath, animated: true)
performSegueWithIdentifier("TravelBookDetailSegue", sender: TravelBookTableViewCell())
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
switch indexPath.section{
// 1st custom cell
case 0:
let myProfile = tableView.dequeueReusableCellWithIdentifier("ProfileHeaderCell") as! VideoTableViewCell
myProfile.frame.size = CGSize(width: 600.0, height: 60.0)
return myProfile
// 2nd custom cell
case 1:
let myInfo = tableView.dequeueReusableCellWithIdentifier("AlbumCell") as! AlbumTableViewCell
return myInfo
// 3rd Custom Cell
default:
let cell = tableView.dequeueReusableCellWithIdentifier("TravelBookCell") as! TravelBookTableViewCell
cell.travelBookImage.image = UIImage(named: tableData[indexPath.row])
cell.travelBookTitle.text = tableData[indexPath.row]
return cell
}
}
最佳答案
你可以检查 didSelectRowAtIndexPath:
中的 indexPath.section
委托(delegate)方法,例如,
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
switch indexPath.section{
case 0:
//first segue
break
case 1:
//second segue
break
case 2:
//third segue
break
}
关于ios - 3 tableView Sections with custom Cell Segues swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31645045/