0
votes

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?

3
Its because, you have connected the segue to another ViewController from the cell selection in Storyboard, remove that from cell selection and re-add from ViewController to ViewController, though you will need to call specific segue with their identifiers now.iphonic
@iphonic when you say re-add from viewController to viewController what exactly do you mean. i ctrl drag to the yellow icon on the 2nd and thrid controllers but where do I drag from on the first controller? (if not from a cell selection)user2363025
@iphonic i have removed the segues from cell selection and connected viewControllerA to both viewControllerB and viewControllerC. Now no segues are being performeduser2363025
Yes now you need to call [self performSegueWithIdentifier:@"IDENTIFIER" sender:self]; for specific segue call you need..iphonic
In any case didSelect should be called, if it is not getting called, it might be no delegate set to tableview, or, selection for tableview is turned off from property settings.iphonic

3 Answers

1
votes

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)
    }
}
1
votes

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.

enter image description here

Cheers.

0
votes

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.