所以我试图在tableview中有3个不同的segue和3个不同的section单元格。我正在获取初始tableview以填充自定义单元格数据,但无法将每个单元格设置为segue到每个相应的新ViewController ...所以我想要3个不同segue的单元格...感谢帮助!
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
}
}
答案 0 :(得分:0)
您可以在indexPath.section
委托方法中查看didSelectRowAtIndexPath:
,例如
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
}
答案 1 :(得分:0)
你所做的是当你单击你的单元格时它会调用didSelectRow方法,你只指定了一个segue而没有条件来执行哪个segue。因此,您需要添加if或切换条件,如Akhilrajtr所述。