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 10-08-2009, 07:40 AM   #1 (permalink)
Registered Member
 
Join Date: May 2009
Posts: 23
MattTrout is on a distinguished road
Default Really irritating/annoying If statement problem with Strings in subclass

I have a really annoying problem with this if statement I am trying to get working. I have subclassed UITableViewCell with a custom cell that I am passing data from XML to methods housed in it.

Basically depending on what String is passed, a different image inside the cell will correspond and this is how I planned on setting it (open to other options/suggestions). From what I read I am writing the if statement 100% correct, but it gets skipped over when ran. Thoughts/comments appreciated! The line calling the method from the subclass and the actual method itself are below....

//Calling the method
[cell setTheImage:[[stories objectAtIndex:storyIndex] objectForKey:@"ImageNames"]];


//Method
-(void)setTheImageNSString *)theImg
{
NSLog(theImg); //This displays the correct data in console so that makes it even more annoying that the if statement isn't working!
if([theImg isEqualToString:@"ImageOne"])
{
NSLog(@"Yes");
}
}
MattTrout is offline   Reply With Quote
Old 10-08-2009, 12:15 PM   #2 (permalink)
Registered Member
 
Join Date: Jun 2009
Location: Ypsilanti, Michigan
Age: 63
Posts: 1,549
RLScott is on a distinguished road
Default

How do you know that the "if" statement is being skipped over? Have you proved that theImg is, in fact, "ImageOne"? You know, you could just set as breakpoint in Debug at the "if" statement and then, when you hit it, examine theImg in the debugger to see what it is, and then single-step through the "if" statement to see where it goes.
RLScott is offline   Reply With Quote
Old 10-08-2009, 01:22 PM   #3 (permalink)
Registered Member
 
Join Date: Aug 2009
Posts: 361
pofak is on a distinguished road
Default

Are you sure there is no while space before or after "ImageOne"?

You may want to chane the NSLog to something like:

NSLog([NSString stringWithFormat:"-%@-", theImg]);
pofak is offline   Reply With Quote
Old 10-08-2009, 07:32 PM   #4 (permalink)
Registered Member
 
Join Date: May 2009
Posts: 23
MattTrout is on a distinguished road
Default

Quote:
Originally Posted by RLScott View Post
How do you know that the "if" statement is being skipped over? Have you proved that theImg is, in fact, "ImageOne"? You know, you could just set as breakpoint in Debug at the "if" statement and then, when you hit it, examine theImg in the debugger to see what it is, and then single-step through the "if" statement to see where it goes.
I actually didn't think to step through it. The debugger does show that it was being evaluated and in the summary column it would show the right string (example ImageOne) but it would have a \n at the end (so ImageOne\n). To test if this was the issue I put @"ImageOne\n" in the if statement and still no luck.
MattTrout is offline   Reply With Quote
Old 10-08-2009, 07:35 PM   #5 (permalink)
Registered Member
 
Join Date: May 2009
Posts: 23
MattTrout is on a distinguished road
Default

Quote:
Originally Posted by pofak View Post
Are you sure there is no while space before or after "ImageOne"?

You may want to chane the NSLog to something like:

NSLog([NSString stringWithFormat:"-%@-", theImg]);
Positive there are no white spaces...tried it just to see no luck.
MattTrout is offline   Reply With Quote
Old 10-08-2009, 09:28 PM   #6 (permalink)
Registered Member
 
Join Date: May 2009
Posts: 23
MattTrout is on a distinguished road
Default

Quote:
Originally Posted by MattTrout View Post
I actually didn't think to step through it. The debugger does show that it was being evaluated and in the summary column it would show the right string (example ImageOne) but it would have a \n at the end (so ImageOne\n). To test if this was the issue I put @"ImageOne\n" in the if statement and still no luck.
Update: found a way around what I wanted to do by using compare and doing a switch on the result. Turns out the \n was being included in the string, but if you look at XML doc it's just ImageOne so I have no idea. For some reason though isEqualToString would not work even when I added the \n to the end.
MattTrout is offline   Reply With Quote
Reply

Bookmarks

Tags
custom cell, if statement, strings, uitableviewcell

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: 344
9 members and 335 guests
givensur, glenn_sayers, guusleijsten, ipodphone, mediaspree, mtl_tech_guy, Punkjumper, whitey99, yys
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,649
Threads: 94,114
Posts: 402,883
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Anwerbl
Powered by vBadvanced CMPS v3.1.0

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