ios - removeFromSuperView with Page View Controller -
ios - removeFromSuperView with Page View Controller -
i'm trying close page view controller ibaction button, can close view (pagecontentviewcontroller), new view (loginviewcontroller) showing "dots" page command still here, , can't communicate new view (loginviewcontroller). doing wrong ?
here code :
loginviewcontroller.h :
#import "pagecontentviewcontroller.h" @interface loginviewcontroller : uiviewcontroller <uipageviewcontrollerdatasource> @property (strong, nonatomic) uipageviewcontroller *pageviewcontroller; @property (strong, nonatomic) nsarray *pagetitles; @property (strong, nonatomic) nsarray *pageimages; @end
loginviewcontroller.m :
- (void)viewdidload { [super viewdidload]; // create info model _pagetitles = @[@"over 200 tips , tricks", @"discover hidden features", @"bookmark favorite tip", @"free regular update"]; _pageimages = @[@"first_img.jpg", @"first_img.jpg", @"first_img.jpg", @"first_img.jpg"]; // create page view controller self.pageviewcontroller = [self.storyboard instantiateviewcontrollerwithidentifier:@"pageviewcontroller"]; self.pageviewcontroller.datasource = self; pagecontentviewcontroller *startingviewcontroller = [self viewcontrolleratindex:0]; nsarray *viewcontrollers = @[startingviewcontroller]; [self.pageviewcontroller setviewcontrollers:viewcontrollers direction:uipageviewcontrollernavigationdirectionforward animated:no completion:nil]; // alter size of page view controller self.pageviewcontroller.view.frame = cgrectmake(0, 0, self.view.frame.size.width, self.view.frame.size.height - 30); [self addchildviewcontroller:_pageviewcontroller]; [self.view addsubview:_pageviewcontroller.view]; [self.pageviewcontroller didmovetoparentviewcontroller:self]; } - (pagecontentviewcontroller *)viewcontrolleratindex:(nsuinteger)index { if (([self.pagetitles count] == 0) || (index >= [self.pagetitles count])) { homecoming nil; } // create new view controller , pass suitable data. pagecontentviewcontroller *pagecontentviewcontroller = [self.storyboard instantiateviewcontrollerwithidentifier:@"pagecontentviewcontroller"]; pagecontentviewcontroller.imagefile = self.pageimages[index]; pagecontentviewcontroller.titletext = self.pagetitles[index]; pagecontentviewcontroller.pageindex = index; homecoming pagecontentviewcontroller; } #pragma mark - page view controller info source - (uiviewcontroller *)pageviewcontroller:(uipageviewcontroller *)pageviewcontroller viewcontrollerbeforeviewcontroller:(uiviewcontroller *)viewcontroller { nsuinteger index = ((pagecontentviewcontroller*) viewcontroller).pageindex; if ((index == 0) || (index == nsnotfound)) { homecoming nil; } index--; homecoming [self viewcontrolleratindex:index]; } - (uiviewcontroller *)pageviewcontroller:(uipageviewcontroller *)pageviewcontroller viewcontrollerafterviewcontroller:(uiviewcontroller *)viewcontroller { nsuinteger index = ((pagecontentviewcontroller*) viewcontroller).pageindex; if (index == nsnotfound) { homecoming nil; } index++; if (index == [self.pagetitles count]) { homecoming nil; } homecoming [self viewcontrolleratindex:index]; } - (nsinteger)presentationcountforpageviewcontroller:(uipageviewcontroller *)pageviewcontroller { homecoming [self.pagetitles count]; } - (nsinteger)presentationindexforpageviewcontroller:(uipageviewcontroller *)pageviewcontroller { homecoming 0; }
pagecontentviewcontroller.h :
@interface pagecontentviewcontroller : uiviewcontroller @property (weak, nonatomic) iboutlet uiimageview *backgroundimageview; @property (weak, nonatomic) iboutlet uilabel *titlelabel; @property nsuinteger pageindex; @property nsstring *titletext; @property nsstring *imagefile; - (ibaction)dismissbutton:(id)sender; @end
pagecontentviewcontroller.m :
- (id)initwithnibname:(nsstring *)nibnameornil bundle:(nsbundle *)nibbundleornil { self = [super initwithnibname:nibnameornil bundle:nibbundleornil]; if (self) { // custom initialization } homecoming self; } - (void)viewdidload { [super viewdidload]; self.backgroundimageview.image = [uiimage imagenamed:self.imagefile]; self.titlelabel.text = self.titletext; } - (void)didreceivememorywarning { [super didreceivememorywarning]; // dispose of resources can recreated. } - (ibaction)dismissbutton:(id)sender { [self.view performselectoronmainthread:@selector(removefromsuperview) withobject:nil waituntildone:no]; [self performselectoronmainthread:@selector(removefromparentviewcontroller) withobject:nil waituntildone:no]; } @end
you remove pagecontentviewcontroller not pageviewcontroller (it still there). seek utilize in dismissbutton method [self.view.superview ...
edited:
the way remove parent parent standard code:
[self willmovetoparentviewcontroller:nil]; [self.view removefromsuperview]; [self removefromparentviewcontroller];
but want do, remove parent kid seek utilize code like:
[self.parentviewcontroller willmovetoparentviewcontroller:nil]; [self.parentviewcontroller.view removefromsuperview]; [self.parentviewcontroller removefromparentviewcontroller];
or [self.parentviewcontroller.parentviewcontroller ... depends on hierarchy.
ios uibutton uipageviewcontroller uipagecontrol removechild
Comments
Post a Comment