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

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

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

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.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 12-05-2011, 10:44 AM   #1 (permalink)
jcc
Registered Member
 
Join Date: Aug 2010
Posts: 53
jcc is on a distinguished road
Default NSMutableArray objectAtIndex

Hi,

I have an NSMutableArray that displays a sidebar of various images.I use the following code to notify me of what image was tapped and at what index it was located:

Code:
 

if ([myArray objectAtIndex:anIndex] == [NSNumber numberWithInt:1]){
  
NSLog(@"Touched image at index: %u", anIndex);
NSLog(@"Touched image at 1);      
  
 } else if if ([myArray objectAtIndex:anIndex] == [NSNumber numberWithInt:2]){
  
NSLog(@"Touched image at index: %u", anIndex);
NSLog(@"Touched image at 2);      
  
 }...etc.
The problem I am facing is that I am able to recognize when the user has selected an image up to [NSNumber numberWithInt:12]...but anything higher than 12 the process stops working. Anyone have a clue what might be going on?

Thanks!
jcc is offline   Reply With Quote
Old 12-05-2011, 12:26 PM   #2 (permalink)
Registered Member
 
Join Date: Dec 2011
Posts: 62
Fstuff is on a distinguished road
Default

Quote:
Originally Posted by jcc View Post
Hi,

I have an NSMutableArray that displays a sidebar of various images.I use the following code to notify me of what image was tapped and at what index it was located:

Code:
 

if ([myArray objectAtIndex:anIndex] == [NSNumber numberWithInt:1]){
  
NSLog(@"Touched image at index: %u", anIndex);
NSLog(@"Touched image at 1);      
  
 } else if if ([myArray objectAtIndex:anIndex] == [NSNumber numberWithInt:2]){
  
NSLog(@"Touched image at index: %u", anIndex);
NSLog(@"Touched image at 2);      
  
 }...etc.
The problem I am facing is that I am able to recognize when the user has selected an image up to [NSNumber numberWithInt:12]...but anything higher than 12 the process stops working. Anyone have a clue what might be going on?

Thanks!
Not entirely clear from the snippet you posted. What makes you say the "process stops working"?

What is the size of your array? Keep in mind the index starts at 0.

Also, how many sections do you have? On iOS, an NSIndexPath object has both a row and a section property. When "-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath" is called, then, you need to account for both section and row.

Hope this helps.

EDIT: It also occurs to me that you are testing whether the object contained at anIndex matches some number. This is different than testing whether or not an object exists at that index.

Last edited by Fstuff; 12-05-2011 at 12:31 PM.
Fstuff is offline   Reply With Quote
Old 12-05-2011, 12:31 PM   #3 (permalink)
Registered Member
 
Join Date: Dec 2010
Location: Seattle, WA
Posts: 408
RickSDK is on a distinguished road
Default

the problem is the your array returns a string, but you are trying to compare it using "==" which is for numbers. So you need to either compare strings or numbers. either of these would work:

if ([[myArray objectAtIndex:anIndex] intValue] == 1)


if ([[myArray objectAtIndex:anIndex] isEqualToString:@"1"])
__________________
Check out my apps

RickSDK is offline   Reply With Quote
Old 12-05-2011, 12:31 PM   #4 (permalink)
jcc
Registered Member
 
Join Date: Aug 2010
Posts: 53
jcc is on a distinguished road
Default

Quote:
Originally Posted by Fstuff View Post
Not entirely clear from the snippet you posted. What makes you say the "process stops working"?

What is the size of your array? Keep in mind the index starts at 0.

Also, how many sections do you have? On iOS, an NSIndexPath object has both a row and a section property. When "-(UITableViewCell *)tableViewUITableView *)tableView cellForRowAtIndexPathNSIndexPath *)indexPath" is called, then, you need to account for both section and row.

Hope this helps.
Thanks for you reply. I found the problem. It appears that other people have had the same issue.

"Basically, numbers up to (and including) 12 give you a reference to an already existing NSNumber, something which is possible due to the fact that they're immutable. Investigation showed that numbers 13 or greater gave a separate instance." objective c - NSNumber >= 13 won't retain. Everything else will - Stack Overflow

Additionally, the following post addressed my problem perfectly. objective c - NSNumber numberWithInt crashing on numbers >= 13 - Stack Overflow
jcc is offline   Reply With Quote
Reply

Bookmarks

Tags
nsmutablearray

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: 406
13 members and 393 guests
7twenty7, AppsBlogger, David-T, Duncan C, EvilElf, HemiMG, heshiming, iekei, LunarMoon, Murphy, sacha1996, Sami Gh, teebee74
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,676
Threads: 94,127
Posts: 402,915
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jleannex55
Powered by vBadvanced CMPS v3.1.0

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