Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

UINavigationController's UIToolBar and global actions

 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've asked this question here as well.

In my application I am using UINavigationController to nav around to different views. I turned on the Shows Toolbar option in the interface builder for my UINavigationController. I understand how to add items to this toolbar. However, I have a couple of items that will be the same throughout the entire application, they show up on every view; Logout & Menu.

I'm looking for a way to attach events to these buttons on each controller so that the same method is called. What I mean is, I don't want to have to write the IBAction methods in every controller. This would duplicate the same logic 10+ times.

Thanks for any advice.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Objective-C does have inheritence. ;)

Maybe create a base interface/class that all your controller's extend, then they all will have the same IBAction. You can even not implement the action in the controllers, but delegate it even more. Maybe the delegation is overkill.

It is really easy for me to lose all the great OO stuff that I usually do in Java, when I am coding Objective-c. But I think in the long run, all of us would be better to get into the habit of doing good OO in iPhone development.

And Gregg, you can be the Guinea Pig. Let me know how it goes. ;)

Mark
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mark, that's all I needed; a nudge in the right direction. Here's how I accomplished this...





Some boilderplate left out for brevity. Works like a champ. Thanks, Mark.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic