Reputation: 6515
I have a table view with a few different prototype cells. I want to have one prototype cell segued to one controller and the rest should not be clickable i.e. no seg.
Right now, I have one button linked to a controller successfully but when I tap on the tableview prototype cell which is segued to a different controller (in the storyboard) nothing happens. I don't get any error either.
What is the best way to go around this? Can I make two different segues in the storyboard? Or do I need to implement something in the tableview method did select row at index path, somehow grab the class associated with the row clicked and programmatically segue to a different screen? Something like: func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { println("here") //self.performSegueWithIdentifier("profileSeg", sender: self) }
I am not getting the println here when I select a cell and yes I have assigned the delegate in viewdidload.
EDIT
I've just realised I made a mistake when explaining the question. I actually have a view at the bottom which links to one view controller. It is not a tableview row... This is the seg that works. But I have ctrl dragged to from one type of cell to a second controlleR and that seg is not working. There are also 3 other types of cells none of which have segs attached. Is this anything to do with the issue?
Upvotes: 0
Views: 1472
Reputation: 12717
If didSelectRowAtIndexPath
not working, it can be caused by either your UITableViewDelegate
has not been set, or, it might possible that Selection of your UITableView has been turned off, need to Turn on, see image to find how.
Cheers.
Upvotes: 1
Reputation: 672
Don't segue directly from cell to 'ViewController', you must segue cell 'ViewController' to the other 'ViewController'. You can segue many times from 'ViewController'.
And please add this code
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
println("You selected cell #\(indexPath.row)!")
if indexPath.row == 0{
performSegueWithIdentifier("profileSeg", sender: self)
}else{
performSegueWithIdentifier("anySeg", sender: self)
}
}
Upvotes: 1
Reputation: 679
There are two ways to do what you want:
First if you only want to link ONE TVCell with one ViewController you could do what you started to do: Link every TVCell with the ViewController you want to go from there. For that hold ctrl and drag and drop from the prototype to the ViewController. So every TVCellPrototype can have one segue and if you hit the cell it will automatically perform the segue. This is also the reason why your code don't prints "profile seg". In this case you don't need to give the segue an identifier.
The second way is better if you need to have MULTIPLE segues from one TVCell to 2 or more ViewControllers. For this you link the ViewController of the TVCells with the ViewControllers you want to go. That way you can set as many segues as you want but you have to give them an identifier because you have to call them in the tableView(... didSelectRowAtIndexPath) function. (click on the segue in interface builder to give it an identifier). This will look like:
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
self.performSegueWithIdentifier("ProfileSeg", sender: AnyObject?())
}
Now lets talk about why you don't get the println("here"): There has to be a mistake according the function because there is no "override" in front of it. In general the compiler won't build your App because it is missing. I don't have all the code so i can't exactly say whats your mistake.
Upvotes: 0