Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/23.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 以编程方式添加的视图对象未显示在情节提要中_Ios_Objective C_Xcode Storyboard - Fatal编程技术网

Ios 以编程方式添加的视图对象未显示在情节提要中

Ios 以编程方式添加的视图对象未显示在情节提要中,ios,objective-c,xcode-storyboard,Ios,Objective C,Xcode Storyboard,我看不到任何以编程方式添加的视图对象。我需要将它们链接到IBAction和/或IBOutlet,但是如果不能ctrl单击并拖动,我就不能 例如,我在viewDidLoad中有以下内容: imageView = [[UIImageView alloc] initWithFrame:CGRectMake(789, 60, 215, 72)]; [imageView setAnimationImages:imgListArray]; [self.view addSubview:imageView];

我看不到任何以编程方式添加的视图对象。我需要将它们链接到
IBAction
和/或
IBOutlet
,但是如果不能
ctrl单击并拖动,我就不能

例如,我在
viewDidLoad
中有以下内容:

imageView = [[UIImageView alloc] initWithFrame:CGRectMake(789, 60, 215, 72)];
[imageView setAnimationImages:imgListArray];
[self.view addSubview:imageView];
动画显示在模拟器中,但不显示在情节提要中


如何使这些对象显示在故事板中(首选),或以编程方式将它们链接到
iActions/Outlets

要将代码实例化对象设置为实例变量,只需将其设置即可。像这样:

// your code 
imageView = [[UIImageView alloc] initWithFrame:CGRectMake(789, 60, 215, 72)];
[imageView setAnimationImages:imgListArray];
[self.view addSubview:imageView];
// and then:
self.myImageView = imageView; // assumes you've got a `@property` called `myImageView`
这与在故事板中构建插座连接的做法完全相同,但现在你自己在做


要设置代码实例化控件的操作,请调用
addTarget:action:forControlEvents:


这与在故事板中设置动作连接完全相同,但现在您自己做了。

正如@vikingsegundo所说,Image Builder允许您将对象添加到视图中,然后将它们连接到类中的IBoutlet和IBActions,但是如果你以编程的方式添加东西,那么你就只能依靠图像生成器/故事板了

您仍然可以创建iVar或属性(首选)来存储对对象的引用,但不需要IBOutlet标记,因此

@property (strong,nonatomic) UIImageView *imageView;
然后

self.imageView = [[UIImageView alloc] initWithFrame:CGRectMake(789, 60, 215, 72)];
[self.imageView setAnimationImages:imgListArray];
[self.view addSubview:self.imageView]; 
您还可以通过代码向对象添加操作处理程序(相当于ctrl拖动到iAction方法)


故事板不像是一个迭代环境。如果你想在视图控制器之间设置视图层次结构和转换,你会发现它们永远不会显示你添加的专业语法。我明白了……我采取的方法完全错误。我已经弄明白了。非常感谢。
[self.aButton addTarget:self action:@selector(buttonEventHandler) forControlEvents: UIControlEventTouchUpInside];