views:

285

answers:

1

Hi,

I've made a custom view to which I add a custom button. This custom view goes as a subview to yet another view (Kal calendar for iphone) that I push into a navigation controller. Now the button in my custom view is connected to an IBAction in which I am not able to call upon the self.navigationController to pop the current view from.

I've tried the [[sender superview] navigationController] for a hierarchy of superview calls but it doesn't work that way either.

Any ideas please?

Thanks

+2  A: 

A view typically has no knowledge of its view controller (and consequently, to its or its superview's view controller's navigation controller) because this would introduce a tight coupling between view and view controller that is usually unwanted and unnecessary.

The easiest way to solve your problem would be to have the view controller instead of the view handle the button's action. If that doesn't work for your design, consider designing a delegate protocol for your custom view and make your view controller the custom view's delegate. The view would then call the delegate method in the button's action method. This latter method is used a lot throughout Cocoa, e.g. by UIScrollView (UIScrollViewDelegate) and UITableView (UITableViewDelegate).

Ole Begemann
My custom view has it's own view controller. I do not get your point saying to have the view controller instead of the view handle the button's action. Can you please elaborate on that point? Thanks a lot
msk
Thanks though Ole, your delegate idea helped. A bit of Googling, and bam!
msk