ios - Showing the same UIBarButtonItem on many views -
i have problem in ios application i'm looking with. i'm relatively new ios programming i'm sure there relatively simple solution problem.
first, i'm going explain hierarchy of application:
- it uses
uitabbarcontroller
show couple of different screens. - it uses
swrevealviewcontroller
show sidebar - the sidebar accessed bar button item present in navigation bar of application.
that application uses swrevealviewcontroller
https://github.com/john-lluch/swrevealviewcontroller doesn't directly affect problem have. if not familiar code base, think of simple bar button shown @ times.
now problem:
- the bar button want show associated few lines of code. (a
property
declaration , methods). - this code should used on major part of different view controllers in application.
now in normal case, i'd subclass uiviewcontroller
, make superclass of views should show button. however, application should show other types of views, such uitableviewcontroller
, subclassing doesn't solve entire problem.
if objective-c
supported multiple inheritance, make class containing code , let other classes extend subclass of uiviewcontroller
, ugly support class @ same time.
notes:
- for now, app based on storyboards
- the
tabbarcontroller
points number ofuinavigationcontroller
s, , not views doesn't have navigation bar. - i have tried implementing
objective-c
category
add category uiviewcontroller setup of uiviewcontroller. got stuck on solution when needed add@property
button , linking xib/storyboard. got idea post add same uibarbuttonitem several uiviewcontrollers doesn't contain details.
tl;dr: want show same uibarbuttonitem
on many of applications views. uibarbuttonitem
associated code, same these views.
what way achieve this?
if understood correctly.
want show button uiviewcontrollers
.
there many ways achieve this. please try one.
1. create subclass of uiview xib. contains button. create properties , ibaction
.
2. implement action on subclass.
3. on .m file write below code
- (id)awakeafterusingcoder:(nscoder *)adecoder { if (![self.subviews count]) { nsbundle *mainbundle = [nsbundle mainbundle]; nsarray *loadedviews = [mainbundle loadnibnamed:@"myview" owner:nil options:nil]; return [loadedviews firstobject]; } return self; }
where, myview name of view.
4. drag , drop uiview
and place on every `uiviewcontroller xib (or storyboard in case) , set custom class "myview" (or name of newly created class).
5. run project.
reference: may you?
Comments
Post a Comment