Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
当我使用子视图调用父视图时,iOS UIPageControl未显示正确的页码_Ios_Objective C_Iphone_Uiviewcontroller_Uipagecontrol - Fatal编程技术网

当我使用子视图调用父视图时,iOS UIPageControl未显示正确的页码

当我使用子视图调用父视图时,iOS UIPageControl未显示正确的页码,ios,objective-c,iphone,uiviewcontroller,uipagecontrol,Ios,Objective C,Iphone,Uiviewcontroller,Uipagecontrol,我有一个包含容器视图的主UIViewController(用flightsetingscontentviewcontroller命名),容器视图是UIPageViewController(用flightsetingcontainer命名) 但是布局必须在主UIViewController(FlightSettingsContentViewController)上设置一个页面控件元素,因此我在主UIViewController上拖动一个页面控件 但是当容器视图(子视图-flightsetingco

我有一个包含容器视图的主
UIViewController
(用
flightsetingscontentviewcontroller
命名),容器视图是
UIPageViewController
(用
flightsetingcontainer
命名)

但是布局必须在主
UIViewController
FlightSettingsContentViewController
)上设置一个页面控件元素,因此我在主
UIViewController
上拖动一个页面控件

但是当容器视图(子视图-
flightsetingcontainer
)加载时,我想设置主视图控制器的页面控件
numberOfPages

我在子视图FlightSettingContainer.m上编写以下代码,以调用父视图控制器pagecontrol页码

 @interface FlightSettingContainer()
 {
     FlightSettingMainViewController *parentFlightSetngVC;
 }

 @implementation FlightSettingContainer

 - (void)viewDidLoad {
     [super viewDidLoad];

 parentFlightSetngVC = (FlightSettingMainViewController*) self.parentViewController;

 [parentFlightSetngVC.pageControl setNumberOfPages:4];

 }
但是在主viewcontroller上,pagecontrol点不会更改为4点


有人知道问题出在哪里吗?非常感谢。

我想当您试图访问
viewdiload
方法中的
parentViewController
对象时,该方法将返回零,因为在
FlightSettingContainer类(子)
视图加载到内存中之前,它不会被设置为
FlightSettingMainViewController(父)的
子对象
。因此,use应该在
viewdideappear或viewWillAppear
中使用您的代码,因为现在它被设置为其父级的子级


希望它能很好地工作:)

您调用代码太早了,关系尚未设置


将其放入
viewdide
方法中

您是否检查了您的parentFlightSetngVC是否有某个对象或它是否为零。使用日志或使用断点检查它。是的,parentFlightSetngVC为零..@@parentFlightSetngVC为什么为零?我得到ParenView控制器有失败代码?parentFlightSetngVC=(FlightSettingMainViewController*)self.parentViewController;谢谢你的代码在视图中将出现或视图确实出现希望它能工作。我把代码放在视图确实出现,它工作了。非常感谢你。请写下答案,我会给你答案。