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

Similar Threads
thread Thread Starter Forum Replies Last Post
Need an array to store unnamed objects adildacoolset iPhone/iPad Programming 6 Jul 14, 2013 04:20 AM
OpenGL ES: Vertex Buffer Objects and Vertex Array Objects Blakeasd iPhone/iPad Programming 2 Jul 12, 2013 11:24 PM
Lockscreen won't respond? blasto2236 iOS 7 1 Jul 6, 2013 03:38 PM
Mac Mini won't respond to system controls? Pandalorian Mac mini 4 Apr 15, 2013 09:17 AM

Forum Jump

All times are GMT -5. The time now is 02:30 AM.

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

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