Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

grandM

macrumors 68000
Original poster
Oct 14, 2013
1,551
309
Yet another question

I get the impression the didSelectRowAtIndexPath is not being used in a splitViewController. I passed in following code in the didSelectRowAtIndexPath. cannot understand why the sender isn't passing the indexPath in following code.

Code:
  override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
        println("\(indexPath) is now ")
        self.performSegueWithIdentifier("showDetailSegue", sender: indexPath)
    }

Then I tried to println the value of sender in prepareForSegue.
Code:
 override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {

        // Get the new view controller using [segue destinationViewController].

        // Pass the selected object to the new view controller.

        println("sender containg \(sender)")

While debugging I'm not seeing any trace of the println("\(indexPath) is now "). Moreover the println("sender containg \(sender)") yields Optional(<UITableViewCell: 0x7ae8dd50; frame = (0 291; 320 44); text = ''; autoresize = W; layer = <CALayer: 0x7ae8df10>>) containing

What am I missing?
 
Is there a segue on your tableviewcell?

The didSelectRowAtIndexPath code is wrong. sender is usually self (and will never be an indexPath). It will normally be a control, or a view, or a view controller.

The second println suggests that there is a segue on your tableviewcell and that is what is calling performSegue:
 
Is there a segue on your tableviewcell?

The didSelectRowAtIndexPath code is wrong. sender is usually self (and will never be an indexPath). It will normally be a control, or a view, or a view controller.

The second println suggests that there is a segue on your tableviewcell and that is what is calling performSegue:
Yes I connected a segue starting from the UITableViewCell. I was already wondering what was calling the performSegue:. Why can't you put anything else in the sender by the way? Seems handy to put in a table or a variable you need in the destinationVC.
 
The concept of the sender comes from Target-Action. The sender is usually a UIControl. The action method passes the sender as a parameter. So if you tap a button the button is sender, it passes self. For performaSegue: the code would normally also pass self as sender (although this is not target action). The sender parameter is a way for the action method to determine who is calling it. So you might have one action method that is called by three different buttons and the action method can do the right thing based on the value of sender. Inside prepareForSegue: the code can also do something different based on the object that called performSegue.

Passing properties to the destinationViewController is done in prepareForSegue:.
 
  • Like
Reactions: grandM
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.