2012-10-30 2 views
0
UIButton * newButton = [UIButton buttonWithType:UIButtonTypeCustom]; 
newButton.imageObject= someImage; 
UIImage * imagePut = someImage.imageBlob; 
imagePut = [imagePut roundedCornerImage:20 borderSize:0]; 
[newButton setImage:imagePut forState:UIControlStateNormal]; 

newButton.frame= CGRectMake(column * self.distanceBetweenButton +marginBetweenButtons, row *self.distanceBetweenButton+marginBetweenButtons, self.sizeOfButtons, self.sizeOfButtons); 
newButton.backgroundColor = [UIColor clearColor]; 
PO(@(newButton.userInteractionEnabled)); 
newButton.userInteractionEnabled=YES; 
[newButton addTarget:self action:@selector(someImageGotPressed) forControlEvents:UIControlEventTouchUpInside]; 
PO(@([newButton allControlEvents])); 
PO(newButton.allTargets); 
[self.collectionOfButton addObject:newButton]; 

간단한 버튼. 문제는 someImageGotPressed가 호출되지 않는다는 것입니다.단추 대신 사용자 상호 작용을 사용하도록 설정해야하는 이유는 무엇입니까?

물론 newButton에는 기본적으로 userInteractionEnabled가 있습니다. 그러나 someImageGotPressed는 여전히 호출되지 않습니다.

대상은 UITableViewCell입니다. 나는 사람들이 버튼과 상호 작용할 것으로 기대하기 때문에 UIinterruptCell에 대한 userinteractionenabled를 해제했다.

다시 켜기 만하면됩니다.

그러나 뭔가가 나를 괴롭힌다. addTarget의 대상은 무엇이든 될 수 있습니다. UIView 또는 UIViewController 일 필요조차 없습니다. 그렇다면 왜 대상에 대한 userInteractionEnabled가 전혀 문제가되지 않습니까?

UITableViewCell이 버튼의 수퍼 뷰이기 때문에보기의 userInteractionEnabled를 끄면 모든 수퍼 뷰 또는 그 종류의 것에서 해제됩니다.

답변

1

수퍼 뷰의 userInteractionEnabled (UITableViewCell)을 NO로 설정하면 모든 자국 방송 사건을 서브 뷰에서도 무시하게됩니다.

+0

대답은 정확하지만 해결책을 제공하지 않습니다. 가능한 해결책은 다음과 같습니다. [link] (http://stackoverflow.com/questions/4661589/how-to-get-touches-when-parent-view-has-userinteractionenabled-set-to-no-in-ios)) – KuramaYoko

관련 문제