NSMutableArray containsObject method not detecting object


NSMutableArray containsObject method not detecting object



// Add the button to the NSMutableArray. ... UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom]; [[self hBtns] addObject:btn]; ...  // In another method, try to see if it exists. - (void)didPushBtn:(id)sender {   UIButton *btn = (UIButton *)sender;   if ([[self hBtns] containsObject:btn]) // Is false every time.   ... } 

Why is it not detecting that the UIButton is in the array?


EDIT

It turns out that it won't even detect it right after it's added:

UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom]; [[self hBtns] addObject:btn]; if ([[self hBtns] containsObject:btn]) // Returns false. 

Getting an iPhone app's product name at runtime?

1:

declaring global variables in iPhone project
Sounds like the isEqual: comparison is failing. Where's the difference between setObject:forKey: and setValue:forKey: in NSMutableDictionary?Can you take a look at the hash for the UIButton in both places (where it's added, and then in didPushBtn) and see if they're the same value?. Why is my UIImageView blurred?
SHowing Activity Indicator View Using Thread Shows This Error in gdb?Unable to push notifications to iPhone in .NET - .PEM certificate problem?

2:

What's the difference between using obj-c accessors and using dot syntax?
I had forgotten to initialize the array (*doh*):. UIWebView scrollBy replacement
[self setHBtns:[[NSMutableArray alloc] initWithCapacity:0]]; 


70 out of 100 based on 55 user ratings 730 reviews