Custom UIButton bypasses tableview: didselectrow?



The chapter on making a custom transparent popover button has me a little confused. First I assume the reason that we do a performselector call is because otherwise you would have to instantiate an instance of the itemviewcontroller class and that would get messy. Second I don’t understand that when you now click your little uibutton icon why this bypasses didselectrow atindexpath such that detailViewController doesn’t display? Seems perfectly convenient but why??


  1. The performSelector stuff allows you to construct your own message and pass them to an object that you don’t know the exact details of. You definitely don’t want to instantiate another ItemsViewController… there is only one, another one would not have its view on the screen and would be useless.

  2. Why does the button get tapped instead of the cell? Think about how views are laid out: a view has subviews, which has subviews, and subviews and so on. When you tap on the button, you are actually tapping on five different views: the button, the cell, the table view itself, the navigation controller’s view, and the window. However, the tap will first go to the button (because it is the deepest subview, or in other words, the frontmost subview), thus, it will take the touch and NOT pass it on to the cell, the table view, or so on. Since the cell never gets the touch, it can’t be selected.


I get it now. Thanks.


Re Custom UIButton.

Could the same results have been effected using some form of delegation i.e. making the ItemsViewController the delegate of the tableCell ?


You certainly could, but because the target-action mechanism is already being used, it makes sense to use it again to relay the message. Delegation is nice when you have an object that can spawn multiple events that it expects one object to handle, because you can neatly define a protocol and all of the messages it might send. In this case, it is much easier to just write this general purpose “append atIndexPath:” method and have all action messages do the same thing.