如何将数组中对象的 UIImageView 添加到视图中?
我有两个对象,一个称为 CollidableController,另一个称为 Collidable。 Collidable 控制器创建 Collidable 并将它们添加到一个数组(在本例中其作用类似于队列),但我正在努力将 Collidable 的 UIImageView 添加到当前视图。在将其添加到数组之前它工作正常,但我无法添加数组中的那个
Collidable *collidable = [[Collidable alloc] init:0];
[leftMovingBytesQueue enqueue:collidable];
//used a category to add this to NSMutableArray so it can act as a queue, this adds the 'collidable' object to the end of the array
[view addSubview:collidable.spriteImage];
collidable.spriteImage.center=CGPointMake(200, 200);
//adding the original collidable object's uiimageview to a view works fine
int length=[leftMovingBytesQueue count]-1;
[view addSubView:[leftMovingBytesQueue objectAtIndex:length].spriteImage];
//this line doesn't work, I get the error Semantic Issue: Property 'spriteImage' not found on object of type 'id'
I have two Objects, one is called CollidableController and the other is Collidable. Collidable controller creates Collidables and adds them to an array (which in this case is acting like a queue) but I'm struggling to add the UIImageView of the Collidable to the current View. It works fine before I add it to the array but I can't add the one that's in the array
Collidable *collidable = [[Collidable alloc] init:0];
[leftMovingBytesQueue enqueue:collidable];
//used a category to add this to NSMutableArray so it can act as a queue, this adds the 'collidable' object to the end of the array
[view addSubview:collidable.spriteImage];
collidable.spriteImage.center=CGPointMake(200, 200);
//adding the original collidable object's uiimageview to a view works fine
int length=[leftMovingBytesQueue count]-1;
[view addSubView:[leftMovingBytesQueue objectAtIndex:length].spriteImage];
//this line doesn't work, I get the error Semantic Issue: Property 'spriteImage' not found on object of type 'id'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用“addSubview”而不是“addSubView”。注意小写的“v”。
试试这个:
您正在排队可碰撞对象。尝试使用 [leftMovingBytesQueue objectAtIndex:0]。数组的最后一个元素可能不是您想要的。
Use "addSubview" not "addSubView". Mind the lowercase 'v'.
Try This:
You are enqueing the collidable object. try with [leftMovingBytesQueue objectAtIndex:0]. The last element of the array might not be what you want.
这应该会让编译器高兴。
This should make compiler happy.
尝试将对象转换为您的自定义类:
Try casting the object into your custom class: