Ios 将动态创建的子视图连接到IBOutlet
我有在应用程序运行时创建的UIImage子视图Ios 将动态创建的子视图连接到IBOutlet,ios,objective-c,subview,Ios,Objective C,Subview,我有在应用程序运行时创建的UIImage子视图 UIImageView *newBlock = [[UIImageView alloc] initWithImage: [UIImage imageNamed:@"image.png"]]; newBlock.frame = CGRectMake(0.0, 0.0, 58.0, 58.0); self.view.userInteractionEnabled = YE
UIImageView *newBlock = [[UIImageView alloc] initWithImage:
[UIImage imageNamed:@"image.png"]];
newBlock.frame = CGRectMake(0.0, 0.0, 58.0, 58.0);
self.view.userInteractionEnabled = YES;
[self.view addSubview:newBlock];
但是,因为它们不存在于界面生成器中,或者至少我找不到它们,所以我无法将我的IBOutlet连接到新图像,因此它们根据计时器移动
timer = [NSTimer scheduledTimerWithTimeInterval:(0.001) target:self selector:@selector(onTimer) userInfo:nil repeats:YES];
pos = CGPointMake(0.0,0.05);
我一直在考虑一种通过代码而不是在界面生成器中链接它们的方法,但是到目前为止,我还没有找到任何关于如何实现这一点的详细信息。任何帮助都将不胜感激。谢谢您无法通过编程方式将视图与interface builder连接,如果我是您,我会尝试用不同的方法解决您的问题。您无法将它们动态连接到IBOutlet。为什么不简单地将所有实例作为变量存储在一个数组中
NSMutableArray *imageViews = [[NSMutableArray alloc] initWithCapacity: X];
...
[imageViews addObject: imageView];
...
for(UIView *view in imageViews)
{
...
}
为UIImageView*newBlock创建实例变量或属性。并在整个范围内参考它。你能进一步解释一下它是如何工作的吗?谢谢?对不起,我没有什么经验,如果我或其他人的答案解决了你的问题,别忘了标记为最佳答案并投票,这样其他有相同问题的ppl就会知道答案。如果没有,请添加评论并寻求更多帮助
NSMutableArray *imageViews = [[NSMutableArray alloc] initWithCapacity: X];
...
[imageViews addObject: imageView];
...
for(UIView *view in imageViews)
{
...
}