나는 썸네일 이미지 그리드를 가지고 있는데, 그 중 하나가 터치되면 전체 이미지를 보여주고 싶습니다. 이제 UIImageView가 터치 이벤트에 응답하지 않지만 this answer에 제안 된대로 이벤트를 처리 할 UIButton을 만들었습니다. 아래 코드 참조 :이미지보기가 터치 이벤트에 응답하지 않습니다
- (void)displayImage
{
NSUInteger i = 0; // The actual code is different and works; this is just for brevity's sake.
// UILazyImageView is a subclass of UIImageView
UILazyImageView *imageView = [[UILazyImageView alloc] initWithURL:[NSURL URLWithString:[[[self images] objectAtIndex:i] thumbnailUrl]]];
UIButton *imageButton = [UIButton buttonWithType:UIButtonTypeCustom];
[imageButton setFrame:[imageView frame]];
[imageButton addTarget:self action:@selector(imageTapped:) forControlEvents:UIControlEventTouchUpInside];
[imageView addSubview:imageButton];
[[self containerView] addSubview:imageView];
[imageView release];
}
}
- (void)imageTapped:(id)sender
{
NSLog(@"Image tapped.");
// Get the index of sender in the images array
NSUInteger index = 0; // Don't worry, I know. I'll implement this later
FullImageViewController *fullImageViewController = [[[FullImageViewController alloc] initWithImageURL:[NSURL URLWithString:[[[self images] objectAtIndex:index] url]]] autorelease];
[[self navigationController] pushViewController:fullImageViewController animated:YES];
}
확인. 그래서 커스텀 버튼을 만들고, 이미지 프레임과 일치하도록 프레임을 설정하고, 내부적으로 반응하고 응답하는 방법에 대해 말하며 이미지의 서브 뷰에 추가했습니다. 하지만 이걸 실행할 때 나는 아무것도 얻지 못합니다. "이미지가 탭되었습니다." 콘솔에 나타나지 않아서 메시지가 전송되지 않는다는 것을 알고 있습니다. 여기서 내가 뭘 잘못하고 있니?
많은 도움을 주셔서 감사합니다.