iphone - What is the best way for a view added via presentModalViewController to communicate its dismissal with the class which invoked the call? -
what best way view added via presentmodalviewcontroller communicate dismissal class invoked call?
in 1 of methods, use presentmodalviewcontroller:animated: popup scoreboard player enters name, clicks ok. working fine scoreboard, when use dissmissmodaleviewcontroller i'd way class called presentmodeviewcontroller display alert.
i tried following in method called presentmodalviewcontroller:
[self presentmodalviewcontroller:"mynib" animated:yes]; [alert show];
but alert code runs after presentmodalviewcontroller runs, assume when presentmodalviewcontroller called, doesn't stop code executing outside of it.
anyway, need alert options handled within class calls presentmodalviewcontroller, best way go it?
in opinion best implementing protocol , suscribe caller class delegate of scoreview, try implementing in scoreview header file:
@portocol scoreviewdelegate <nsobject> - (void)userdidenterdata:(nsstring *)data; @end @interface scoreview:.... { // instance variable ... id <scoreviewdelegate> delegate; // delegate shouldn't pointer } @property (assign) id <scoreviewdelegate> delegate; ... @end
inside scoreview class implementation should have method handles user interactions when done inserting data method must send message it's delegate:
@implementation scoreview @synthesize delegate; // don't forget synthesize delegate - (ibaction)userisdone:(id)sender { // stuff [delegate userdidenterdata:self.atextfield.text]; } ... @end
now, code should send message caller class shoul suscribed delegate must this:
@interface callerclass:nsobject <socreviewdelegate> { ... @end @implemetation callerclass ... scoreview *sview = ....; sview.delegate = self; //because it's suscribed delegate, should implement method - (void)userdidenterdata:(nsstring *)data { // here have data // present alert }
i hope found useful case.
Comments
Post a Comment