Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Jul 19, 2011, 02:15 PM   #1
xcodeNewbie
macrumors member
 
Join Date: Jul 2011
Objects in Array Won't respond

I have an NSMutableArray, called myArray. No matter what I do, the objects in it won't respond to any command. Take a look at this code:
Code:
UIImageView *myView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"pic.jpg"]];
myView.frame = CGRectMake(0,0,100,100);
[self.view addSubview:myView];
[myView release];
The above code works perfectly, a UIImageVIew is created in the top left corner of the screen. However, look at this code:
Code:
UIImageView *myView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"pic.jpg"]];
myView.frame = CGRectMake(0,0,100,100);
[myArray replaceObjectAtIndex:0 withObject:myView];
[self.view addSubview:[myArray objectAtIndex:0]];
[myView release];
With this code, no ImageVIew appears. I've been having trouble for so long with Arrays, it's like when an object is in an array it becomes invisible and unusable.
xcodeNewbie is offline   0 Reply With Quote
Old Jul 19, 2011, 02:25 PM   #2
dejo
Moderator
 
dejo's Avatar
 
Join Date: Sep 2004
Location: The Centennial State
Time for some basic debugging. What is the value of myArray when you call replaceObjectAtIndex:withObject? Is it non-nil? Has it been initialized? Etc.

P.S. How and where is myArray defined?
__________________
dejo is offline   0 Reply With Quote
Old Jul 19, 2011, 02:27 PM   #3
xcodeNewbie
Thread Starter
macrumors member
 
Join Date: Jul 2011
myArray

It was initialized with an object count of 1.
xcodeNewbie is offline   0 Reply With Quote
Old Jul 19, 2011, 02:41 PM   #4
RonC
macrumors regular
 
Join Date: Oct 2007
Location: Chicago-area
Quote:
Originally Posted by xcodeNewbie View Post
It was initialized with an object count of 1.
Huh? Do you mean you created it with a capacity of 1? I don't believe that adds ANY objects in the array, rather it sets some internal allocation size for possible addition of objects.

Add the following line of code on either side of your "replaceObjectAtIndex:withObject: method:
Code:
NSLog(@"myArray has %d objects in it.",[myArray count]);
Tell us what that prints.
RonC is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
how to stick a string before all the string objects in an array? saleh.hi.62 Mac Programming 5 Nov 8, 2011 02:32 AM
I want an array of ALL the Objects in a Window BadWolf13 Mac Programming 48 Dec 21, 2010 05:09 PM
How to access object properties stored in array? ataylor2009 Mac Programming 13 Mar 26, 2009 11:52 AM
loop, objects and array wierdness kristiaand Mac Programming 4 Nov 6, 2008 05:33 PM
Is there any way to modify a null object in an Array? bigrell486 Mac Programming 1 Apr 15, 2007 04:40 PM


All times are GMT -5. The time now is 04:30 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC