Navigation Design question

2014-04-13 Thread Luther Baker
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:(idMenuOption)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

Re: Navigation Design question

2014-04-13 Thread Maxthon Chan
You can add a category on UIViewController, do some detection and swizzle 
-[UIViewController viewWillAppear:] method.

On Apr 14, 2014, at 5:55, Luther Baker lutherba...@gmail.com wrote:

 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:(idMenuOption)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/xcvista%40me.com
 
 This email sent to xcvi...@me.com



signature.asc
Description: Message signed with OpenPGP using GPGMail
___

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

Re: Navigation Design question

2014-04-13 Thread Steve Christensen
Why not just make a common UIViewController subclass that manages the global 
menu button, and then subclass that class for each of the controllers that live 
on your navigation stack? If it contains the ivar for the UINavigationItem 
(marked @protected) instead of having that ivar in each of the custom 
controllers, then it has access to it to manage the global menu button, and the 
subclasses can also perform whatever custom bits are required. It also means 
that each of the sub-subclasses don’t need to be calling -addBarButtonItem:… or 
know how the global menu works. The controller class that knows about the 
global menu button then implements -addMenuOption: (not 
-addMenuOption:navigationItem:, since it already knows the navigation item) and 
the sub-subclasses call it to add an option.


On Apr 13, 2014, at 2:55 PM, Luther Baker lutherba...@gmail.com wrote:

 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:(idMenuOption)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/punster%40mac.com
 
 This email sent to puns...@mac.com


___

Cocoa-dev mailing list