ios - Trying to dismiss a popover that was presented by storyboard -




i see lot of questions on answers nothing me.

i presenting popover using storyboard. after while want dismiss popover programmatically.

i have tried many things last try involves creating class view controller inside popover. class this:

- (id)initwithcoder:(nscoder *)adecoder {   self = [super initwithcoder:adecoder];   if (self) {     [self initializenotification];   }   return self; }   - (void) initializenotification {   [[nsnotificationcenter defaultcenter]    addobserverforname:@"closepopover"    object:self    queue:[nsoperationqueue mainqueue]    usingblock:^(nsnotification * _nonnull note) {      [self dismissviewcontrolleranimated:yes completion:nil];    }]; } 

then, main code post notification like

  [[nsnotificationcenter defaultcenter]     postnotificationname:@"closepopover"                   object:self]; 

and nothing happens... popover continues there.

why?

you have replace self nil (for object parameter) when creating notification observer since not self posts notification:

[[nsnotificationcenter defaultcenter] addobserverforname:@"closepopover" object:nil queue:[nsoperationqueue mainqueue] usingblock:^(nsnotification * _nonnull note) {     [self dismissviewcontrolleranimated:yes completion:nil]; }]; 




wiki

Comments

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

python - Read npy file directly from S3 StreamingBody -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -