Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/118.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.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-在UIViewController子类中连接插座的位置?_Ios_Objective C_Cocoa Touch_Uiviewcontroller_Interface Builder - Fatal编程技术网

ios-在UIViewController子类中连接插座的位置?

ios-在UIViewController子类中连接插座的位置?,ios,objective-c,cocoa-touch,uiviewcontroller,interface-builder,Ios,Objective C,Cocoa Touch,Uiviewcontroller,Interface Builder,我对UIViewController(我们称之为ParentViewController)进行了子类化,并添加了一系列属性和方法——IBOutlets和IBActions等等——我想为ChildViewControllerA,ChildViewControllerB,ChildViewControllerC等子类化 我愚蠢的问题是,既然所有这些属性都是在ParentViewController的界面中定义的,那么如何在ChildViewControllers界面中连接它们呢?在我的ios 7故事

我对
UIViewController
(我们称之为
ParentViewController
)进行了子类化,并添加了一系列属性和方法——IBOutlets和IBActions等等——我想为
ChildViewControllerA
ChildViewControllerB
ChildViewControllerC
等子类化

我愚蠢的问题是,既然所有这些属性都是在
ParentViewController的
界面中定义的,那么如何在
ChildViewControllers
界面中连接它们呢?在我的ios 7故事板主文件中,我为
ChildViewControllerA
ChildViewControllerB
、ChildViewControllerC等中的每一个都有一个ViewController,但我在它们相应的.h/.m文件中没有小加号端口,因为它们都在
ParentViewController.h


有什么我遗漏的吗?我是否需要重新定义每个
ChildViewController
中的属性,以便有地方将它们连接到相应的故事板视图?

您尝试做什么?如果尝试将参数传递给其他视图控制器,请在ParentViewController中使用此方法:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
     [segue.destinationViewController yourInitializationMethod:withProperties];
}

这应该按照您描述的方式工作;正如我刚才证实的那样

@interface ParentViewController : UIViewController
@property (nonatomic, weak) IBOutlet UILabel *someLabel;
@end
创建
ParentViewController
的子类,并将脚本编辑器中的自定义类设置为
ChildViewControllerA
ChildViewControllerB
,如下所示:

如果这与你正在做的事情相符,插座应该在那里


简言之,您不需要重新定义对象层次结构中先前定义的出口。

逻辑非常简单,如果您继承任何类,那么这些出口将可用于继承它的所有其他类。例如

在您的情况下,您有
家长
,其中您有一个插座,比如说
按钮a
。现在,其他类
Child1
Child2
继承了
Parent
,它们可以访问
ButtonsA
,但是如果您创建了
Child1
Child2
的任何出口,并且如果没有其他类继承它,它将不适用于任何类,也不适用于
Parent
。。如果要访问属性,可以将
子控制器
作为属性包含在任何一个类中


希望这能有所帮助。

感谢您提供清晰的屏幕截图!这可能是不相关的,但由于某种原因,我连接的UIImageView(在ChildViewControllerA的nib和ChildViewControllerA.h之间)没有出现。。在调试器中,即使我正在设置(UILabel*)propA.text=newString,UIImage和UILabels的变量似乎也没有改变。它默认为nib中的任何内容,在我将其子类化之前,它会覆盖nib中的内容。不确定,在没有看到代码上下文的情况下会发生什么。你有没有可能在插座加载之前进行这些更改?您可以实现
awakeFromNib
并查看。在属性名称之前添加了“self.”,(UILabel*)self.propA.text=newString,这就解决了这个问题。更相关的一点是,稍微值得关注的是,即使在ParentViewController中,属性似乎也连接起来了,但随着我创建更多的ChildViewController,ParentViewController中定义的属性不可能连接到所有的nib视图,对吗?很好。如果我正确理解了您的问题,
ParentViewController
本质上是一组类的抽象超类,您可以通过加载故事板来实例化这些类。插座连接是针对每个孩子的;你可以在编辑器中一个接一个地编辑它们。还是我误解了你的问题?你理解对了!非常感谢。“编辑器中的1-by-1”非常有意义,1是每个ChildViewController的自定义nib,但另1是ChildViewController.h文件的出口。。。还是从你的图片?屏幕截图中的图形似乎表明我不需要ChildViewController.h文件中的相应属性定义,如果为单个ChildViewController UIVC NIB正确输入了“自定义类”名称,则注册是自动的,即使仅从ChildViewController.h文件看不到(没有定义)。对的