Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: A bit stumped....



You can't compare NSStrings with the == operator. Basically what you're doing there is comparing the addressed stored in the pointers. You can use the isEqualTo: method to compare two strings:

if ([rwdString isEqualTo:readString])
etc.

Also, it's probably a better idea to use indexOfSelectedItem with constants for the item indices instead of titleOfSelectedItem, in case you want to localize the program late.

Jeff Binder

On Friday, July 20, 2001, at 10:49 AM, email@hidden wrote:

Hey all, I'm hoping someone can figure this one out.

I've set up an NSPopupButton in IB. It has three menu items - Read, Write, and Delete.

In PB, I'm using if statements to try to get which item is selected. I've set up one string to be [rwdMenu titleOfSelectedItem] and three other strings that are just set to Read, Write, and Delete. But the if statements won't work! Using NSLog, I can see that the rwdString is either Read, Write, or Delete, depending on which item is selected, but if I do this:

if ( rwdString == readString )
NSLog (@"It's equal to Read");
else if ( rwdString == writeString )
NSLog (@"It's equal to Write");
else if ( rwdString == deleteString )
NSLog (@"It's equal to Delete");
else
NSLog (@"It's not equal to any of those, it's \"%@\"", rwdString);

It ALWAYS tells me it's not equal to any of the strings, though with the last NSLog entry, I see either Read, Write, or Delete. What gives? Is the titleOfSelectedItem in some other encoding than the other strings? Or will this just not work (I hope that's not the answer, it would make things difficult!)?

Thanks for any help,

Mike (aka Darkshadow)
_______________________________________________
cocoa-dev mailing list
email@hidden
http://www.lists.apple.com/mailman/listinfo/cocoa-dev


References: 
 >A bit stumped.... (From: email@hidden)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.