如何将数组中对象的 UIImageView 添加到视图中?

发布于 2024-11-18 13:54:34 字数 845 浏览 2 评论 0原文

我有两个对象,一个称为 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

﹏雨一样淡蓝的深情 2024-11-25 13:54:34

使用“addSubview”而不是“addSubView”。注意小写的“v”。
试试这个:

Collidable  *collidableObj=(Collidable*)[leftMovingBytesQueue objectAtIndex:0];
UIImageView* imView=collidableObj.spriteImage; //just checking
[view addSubview:imView];

您正在排队可碰撞对象。尝试使用 [leftMovingBytesQueue objectAtIndex:0]。数组的最后一个元素可能不是您想要的。

Use "addSubview" not "addSubView". Mind the lowercase 'v'.
Try This:

Collidable  *collidableObj=(Collidable*)[leftMovingBytesQueue objectAtIndex:0];
UIImageView* imView=collidableObj.spriteImage; //just checking
[view addSubview:imView];

You are enqueing the collidable object. try with [leftMovingBytesQueue objectAtIndex:0]. The last element of the array might not be what you want.

扎心 2024-11-25 13:54:34
[view addSubView:[[leftMovingBytesQueue objectAtIndex:length] spriteImage]];

这应该会让编译器高兴。

[view addSubView:[[leftMovingBytesQueue objectAtIndex:length] spriteImage]];

This should make compiler happy.

安稳善良 2024-11-25 13:54:34

尝试将对象转换为您的自定义类:

[view addSubView:(Collidable*)[leftMovingBytesQueue objectAtIndex:length].spriteImage];

Try casting the object into your custom class:

[view addSubView:(Collidable*)[leftMovingBytesQueue objectAtIndex:length].spriteImage];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文