ios - Warning: Attempt to present * whose view is not in the window hierarchy -


first of want thank of you! :)

so, have main view controller table view, custom cells class. have made custom selection of cell (you have slide cell of view). in action i'm calling method in main view controller send sms. i'm getting warning, , sms controller not appearing. know, error message means, can't open sms controller, because main controller not loaded? tried codes here, nothing works me. classes this:

main controller.m  . . .  -(void)viewwillappear:(bool)animated {     [self.citiesbutton settitle:rowvalue forstate:uicontrolstatenormal];      uitableview *tableview = (id)[self.view viewwithtag:1]; {     tableview.rowheight = 100;     uinib *nib  = [uinib nibwithnibname:@"tableviewcell" bundle:nil];     [tableview registernib:nib forcellreuseidentifier:celltableidentifier];      uiedgeinsets contentinset = tableview.contentinset;     contentinset.top = 20;     [tableview setcontentinset:contentinset];      nslog(@"rowvalue %@", rowvalue);     self.city = [_dict objectforkey:rowvalue]; }      nslog(@"view appear");     [tableview reloaddata]; }  -(void)sendsms {     mfmessagecomposeviewcontroller *controller = [[mfmessagecomposeviewcontroller alloc] init];     if([mfmessagecomposeviewcontroller cansendtext])      {         controller.body = @"testy test";         controller.recipients = [nsarray arraywithobjects:@"774252704", nil];         controller.messagecomposedelegate = self;          [self dismissviewcontrolleranimated:yes completion:^{         [self presentviewcontroller:controller animated:yes completion:nil];     }];  } } 

so i'm trying close main controller first , display smscontroller, still no luck. think, problem in i'm calling method tableviewcell class, still, table created after view loaded, i'm lost here.

thank time!

=====edit=====

here custom cell class, call sendsms method

tableviewcell.m  #import "tableviewcell.h" #import "tableviewcontroller.h"  static nsstring *celltableidentifier = @"tableviewcell";  @implementation tableviewcell  @synthesize timelabel = _timelabel; @synthesize pricelabel = _pricelabel; @synthesize infolabel = _infolabel;   - (void)awakefromnib {     // initialization code }   -(void)layoutsubviews {     uipangesturerecognizer *pangesture = [[uipangesturerecognizer alloc] initwithtarget:self action:@selector(pangesturerecognizer:)];      [self addgesturerecognizer:pangesture]; }   -(id)initwithstyle:(uitableviewcellstyle)style reuseidentifier:(nsstring *)reuseidentifier {      self = [super initwithstyle:style reuseidentifier:celltableidentifier];        return self; }  - (void)setselected:(bool)selected animated:(bool)animated {     [super setselected:selected animated:animated];      // configure view selected state }  -(void)pangesturerecognizer:(uipangesturerecognizer *)sender{     cgpoint translation = [sender translationinview:self];      tableviewcontroller *maincontroller = [[tableviewcontroller alloc] init];      //nslog(@"panned translation point: %@", nsstringfromcgpoint(translation));      sender.view.center = cgpointmake(sender.view.center.x + translation.x,                                  sender.view.center.y);       cgpoint breakingpoint = cgpointmake(320,sender.view.center.y);     cgpoint startpoint = cgpointmake(150, sender.view.center.y);     cgpoint endpoint = cgpointmake(500, sender.view.center.y);      if (sender.view.center.x <= startpoint.x) {         sender.view.center = startpoint;     }      if (sender.state == uigesturerecognizerstateended) {         if (sender.view.center.x >= breakingpoint.x) {              [uiview animatewithduration:0.2                               delay:0.0                             options: uiviewanimationoptioncurveeaseout                          animations:^{                              sender.view.center = endpoint;                          }                          completion:^(bool finished){                              nslog(@"bought!");                              [maincontroller sendsms];                          }];      } else {         //recognizer.view.center = startpoint;          [uiview animatewithduration:0.2                               delay:0.0                             options: uiviewanimationoptioncurveeaseout                          animations:^{                              sender.view.center = startpoint;                          }                          completion:^(bool finished){                              nslog(@"returned!");                          }];     } }     [sender settranslation: cgpointzero inview: self]; } 

- (void)presentviewcontroller:(uiviewcontroller *)viewcontroller animated:(bool)animated oncomplete:(void (^)(void))callback {     appdelegate *app_delegate = [uiapplication sharedapplication].delegate;      uiviewcontroller *presentedmodalvc = [app_delegate.window.rootviewcontroller presentedviewcontroller];      if (presentedmodalvc) {         while (presentedmodalvc.presentedviewcontroller) {             presentedmodalvc = presentedmodalvc.presentedviewcontroller;         }         [presentedmodalvc presentviewcontroller:viewcontroller animated:animated completion:callback];     } else {         [app_delegate.window.rootviewcontroller presentviewcontroller:viewcontroller animated:animated completion:callback];     } }  -(void)sendsms {     mfmessagecomposeviewcontroller *controller = [[mfmessagecomposeviewcontroller alloc] init];     if([mfmessagecomposeviewcontroller cansendtext])      {         controller.body = @"testy test";         controller.recipients = [nsarray arraywithobjects:@"774252704", nil];         controller.messagecomposedelegate = self;          [self presentviewcontroller:controller animated:yes oncomplete:nil];     }               } 

you must present vc on presented vc, if exist, i.e. if have hierarchy of presented vc's

 vc1---     vc2 - presented vc1-----       vc3 - presented vs2----   ...         vcx - presented x-1  

then must present new vc on vcx, i.e. on last vc presented/visible.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -