문제

// 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.
도움이 되었습니까?

해결책 2

배열을 초기화하는 것을 잊었습니다 (*doh*).

[self setHBtns:[[NSMutableArray alloc] initWithCapacity:0]];

다른 팁

처럼 들린다 isEqual: 비교가 실패합니다. 당신은 hash 두 곳의 Uibutton을 위해 (추가 된 곳, 그리고 didPushBtn) 그리고 그들이 같은 가치인지 확인하십시오.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top