Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 01-12-2010, 12:13 PM   #1 (permalink)
Registered Member
 
Join Date: Jan 2010
Posts: 12
Default Adding UIImageView to NSMutableArray

Hi all

I am having trouble adding UIImageViews to a NSMutableArray.

in my .h file i have:

Code:
@interface iWackViewController : UIViewController {
	NSMutableArray *monsterList;
}

@property (nonatomic) NSMutableArray *monsterList;
in my .m i try this:

Code:
CGRect myImageRect = CGRectMake(0, 0, 16, 16);
UIImageView *myImage = [[UIImageView alloc] initWithFrame:myImageRect];
[myImage setImage:[UIImage imageNamed:@"monster.png"]];
myImage.opaque = YES;
[self.view addSubview:myImage];
[monsterList addObject:myImage];
NSLog(@"Monster added.");
NSLog(@"Array now %i elements long",monsterList.count);
But my array never grows - in the console i get "Monster added" followed by "Array now 0 elements long. The UIImageView is displayed just fine in the simulator.

Anyone know what i am doing wrong?

I want the array to be "public" i whatever you would call it in Objective C, which is why i define it in my .h

Thanks in advance.
nibby is offline   Reply With Quote
Old 01-12-2010, 01:05 PM   #2 (permalink)
Game Developer
 
Join Date: Jul 2009
Location: Austria
Posts: 65
Default

You need to write the NSMutableArray into the .m file:

Code:
monsterList = [[NSMutableArray alloc] init];
nitrorazor is offline   Reply With Quote
Old 01-12-2010, 01:11 PM   #3 (permalink)
Registered Member
 
Join Date: Jan 2010
Posts: 12
Default

Quote:
Originally Posted by nitrorazor View Post
You need to write the NSMutableArray into the .m file:

Code:
monsterList = [[NSMutableArray alloc] init];
Rookie mistake - thanks...
nibby is offline   Reply With Quote
Reply

Bookmarks

Tags
nsmutablearray, uiimageview

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 248
24 members and 224 guests
ADY, AragornSG, bookesp, chillyh, dacapo, Dani77, Davey555, Dominus, dre, glenn_sayers, HemiMG, JasonR, karlam963, LEARN2MAKE, M.A.S., marshusensei, mer10, nobre84, Oral B, prchn4christ, Raggou, Rudy, spiderguy84, themathminister
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,885
Threads: 89,230
Posts: 380,765
Top Poster: BrianSlick (7,129)
Welcome to our newest member, bookesp
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 02:27 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0