하위 뷰 UILabel을 사용하여 UIScrollView에 액세스하는 방법을 알고 싶습니다.
UIScrollView에 액세스하려고했습니다 .superview
. 그러나 나는 지금 오류를 받고 있습니다
No visible @interface for 'UIView' declares the selector 'scrollRectToVisible:animated:'
내가 사용하는 코드는 다음과 같습니다.
- (void) SymbolButtonPressed:(NSString *)selectedString {
UILabel *label = (UILabel *)[self.view viewWithTag:currentlySelectedTag];
// perform scrolling here, figure out what view your uilable is in.
float newPosition = label.superview.contentOffset.x+label.frame.size.width;
CGRect toVisible = CGRectMake(newPosition, 0, label.superview.frame.size.width, label.superview.frame.size.height);
[label.superview scrollRectToVisible:toVisible animated:YES];
}
의 수퍼 뷰는 UILabel
유형 UIView
이므로 호출하려는 메소드에 응답하지 않습니다. UIScrollView
Xcode가 액세스하려는 메서드와 속성을 볼 수 있도록 superview를로 캐스팅 할 수 있습니다 . 수퍼 뷰가 메소드에 응답하는지 확인해야합니다.
if([label.superview respondsToSelector:@selector(scrollRectToVisible:animated:)]) {
[(UIScrollView *)label.superview scrollRectToVisible:toVisible animated:YES];
}
샘플 코드가 주어지면 contentOffset을 얻기 위해 superview를 캐스팅해야합니다.
float newPosition = ((UIScrollView *)label.superview).contentOffset.x+label.frame.size.width;
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다