ios - Can't send a UIButton event to other view controller correctly -
can provide examples , formal patterns one-to-one event transfer between uiviewcontroller
s? think nsnotificationcenter
not applicable use case because based on event bus , broadcasting patterns broad state changes , that's why should used one-to-many transfers. know kvo
not applicable in case at all too, because used communication between model , controller layers in classical mvc
realm. know 1 way one-to-one event transfers: delegate pattern. may there more elegant , simple
not easy
solutions.
for example:
in view action sent to:
@protocol mapviewdelegate <nsobject> @required -(void)mapimagebuttonclicked:(uibutton*)sender; @end @interface mapview : uiview { uibutton *mapbutton; id mapviewdelegate; } @property(nonatomic,retain) id mapviewdelegate; @property(nonatomic,retain) uibutton *mapbutton;
.m
[mapbutton addtarget:self.delegate action:@selector(mapimagebuttonclicked:) forcontrolevents:uicontroleventtouchupinside];
in view action sent from:
#import "mapview.h" @interface mapviewcontroller : uiviewcontroller<mapviewdelegate> { } .m mapview *map = [[mapview alloc] init]; map.delegate = self; -(void)mapimagebuttonclicked:(uibutton*)sender { //implement necessary functionality here }
hope idea. please implement according situation.
Comments
Post a Comment