objective c - How should I implement [almost] identical actions used throughout various VCs? (Answer: use a category) -
right using delegate, suspect it's bad form.
i programatically create identical uibarbuttonitem
in numerous, different view controllers.
my button's target myappdelegate
, , action defined therein.
what better way of doing this? or supposed copy , paste identical action no-matter-how-many view controllers instantiate identical bar button?
okay, suppose action identical in respects one: varies in should send presentviewcontroller message view controller instantiated button sent action. thus, in action, can send presentviewcontroller
message sender
, instance of button, know no means of reaching view controller instantiated instance of button.
each view controller needs set target of button when button created. button's action selector sent correct controller.
as selector itself, create category on uiviewcontroller
contain button's action:
@implemenation uiviewcontroller (mkcbarbuttonitemaction) - (void)mkcdothatthingido { // things. [self presentviewcontroller:[self theotherviewcontrollerwhatineedtodisplay] animated:yes completion:^{ // more things. }]; // yet other things. } @end
Comments
Post a Comment