// 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.
...
}
为什么没有检测到 UIButton 在数组中?
编辑
事实证明,它甚至不会在添加后立即检测到它:
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
[[self hBtns] addObject:btn];
if ([[self hBtns] containsObject:btn]) // Returns false.