Hello all,

I've run into an issue a few times and I'd like to see if someone has a
good design suggestion to address my problem.

Consider an iPad or iPhone application based on a UINavigationController -
that displays a 'menu' button in the UINavigationBar. The navbar renders
UIBarButtonItems ... which we set per the UIViewController level via the
UINavigationItem which is available to us via the UIViewController.

Now, I've got to render, for lack of a better term, a _global_ menu. I need
the exact same button to simply stick to the upper left or right hand side
of the nav bar. Consider that the button triggers the display of a
UIPopoverController with a tableview which again, has _global_ style
options. Specifically, and to keep the example simple, this menu has
nothing to do with the child view controller. Maybe menu options include
LOGOUT, or display SETTINGS or maybe there is an option to modally presents
a report.

How can I get this to show up - without forcing every single view
controller to _know_ about this global menu, jam it into their own
self.navigationItem.leftBarButtonItem property and be sure to register a
handler from somewhere to do the right thing.

What I think I _really_ want is a design wherein the view controller
essentially _asks_ the navigation controller to either (a) add a very
specific UIBarButtonItem to the navigation bar (which would allow the
navigation controller to add the button to an array if a global button
already existed) ... or (b) add a selection option - which the navigation
bar could decide how to handle (create a new button, or insert into an
existing menu, etc).

What makes rolling my own wrappers around this difficult is that those
things are set via the UINavigationItem - which is very very specific to
the view controller itself - it isn't directly available to the navigation
controller per se.

I'm leaning towards adding something like:

    - (void)addBarButtonItem:(UIBarButtonItem *)barButtonItem
toNavigationItem:(UINavigationItem *)navigationItem;

    - (void)addMenuOption:(id<MenuOption>)option
toNavigationItem:(UINavigationItem *)navigationItem;

to either a category or subclass of the UINavigationController I am using
to handle the case where I want to _add_ my requirements to whatever the
UINavigationController is already displaying ... the problem is, if a view
controller has _nothing_ to add to the nav bar, the global menu addition
wouldn't get triggered ....

I wonder if I need to shift my focus to the UINavigationBar itself -- and
intercept calls trying to create buttons ... but that be new territory for
me as I've always just depended on the meta-informational style of using
the view controller's UINavigationItem.

Any thoughts on this? Has anyone discovered a better way to do this without
cluttering up every child view controller's SRP with the necessity to set
buttons for someone else while retaining ultimate flexibility to set their
own -- while still not having a way to 'insert' an option into an existing
partially _global_ menu that is floating from vc to vc.

I essentially don't want view controllers setting these items directly - I
want them to _add_ items - not _set_ them. And I'm not sure how to do this
within the design paradigm of the view controller's navigation item
instance - since that just puts me at one more level of direction (someone
else reads that object and then builds out the UINavigationBar accordingly).

Ok - getting wordy and repetitive. Hope I've said enough to be clear what
I'm trying to do.

Thanks,
-Luther
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to