0

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'
8
  • This is a good reason not to create compound statements. In any case, when errors like this appear a good way to debug is to split the compound statement into it's component statements. In this case there are three component statements. When the separate statements work then recombine if that is one's style. Commented Jul 1, 2011 at 14:46
  • I need to add the object's UIImageView in the array though, creating another object from the one in the array and then adding that's UIImageView won't do what I want. Is that possible (maybe using pointers? I've fairly new to them so I'm not sure) Commented Jul 1, 2011 at 14:49
  • @user660582: This does not address your problem, but NSMutableArray has a method lastObject, which you may find useful. Commented Jul 1, 2011 at 14:53
  • THe problem appears to be with the line [leftMovingBytesQueue enqueue:collidable];. Try logging the type of the lastObject after this, and you may find the bug. Commented Jul 1, 2011 at 14:56
  • Try NSLog(@"object type is: %@", [[leftMovingBytesQueue lastObject] class]); Commented Jul 1, 2011 at 15:27

3 Answers 3

1

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.

Sign up to request clarification or add additional context in comments.

9 Comments

the second line gives me this: warning: Semantic Issue: Instance method '-addSubView:' not found (return type defaults to 'id') And then the program quits when it gets there.
I have edited the answer. Try running and see if your collidable object correctly retaining the UIImageView.
Same result. Judging by the comments on the question I think the problem lies elsewhere.
Ah!! I see the error. Use "addSubview" not "addSubView". Mind the lowercase 'v'
That fixed the error but it gives the same result as jmosesman's answer below. When I try to get the type of the object in the array I get null.
|
1
[view addSubView:[[leftMovingBytesQueue objectAtIndex:length] spriteImage]];

This should make compiler happy.

1 Comment

That got rid of the error message but when I tried to run it I got "Program received signal: "SIGABRT"" when it got to that line and I get the warning "Semantic Issue: Instance method '-addSubView:' not found (return type defaults to 'id')"
0

Try casting the object into your custom class:

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

6 Comments

I tried that but I get the same error as before: error: Semantic Issue: Property 'spriteImage' not found on object of type 'id'
And have you set a property on the UIImageView like @property(nonatomic,retain) UIImageView *spriteImage and synthesized it?
Yep, I have. It works when doing it without the array, so I don't think that's the problem.
@jmosesman, @user660582. Shouldn't it be [view addSubView: ((Collidable *)[leftMovingBytesQueue objectAtIndex:length]).spriteImage];?
I'm not sure with the dot syntax. If you did (Collidable*)[leftMovingBytesQueue objectAtIndex:length] spriteImage]; that should work. But you could try adding some extra parentheses.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.