문제

안녕하세요, 현재 뷰의 상위 뷰의 뷰 컨트롤러에 구현된 메서드인 현재 뷰에서 어떻게 호출할 수 있나요?도와 줄수있으세요.고마워요

도움이 되었습니까?

해결책

함수를 추가 할 수 있습니다 -(void) initwithview : (echiquierdisplayview *) asuperview 또는 그와 비슷한 내용을 정의 할 수 있습니다.

@interface pieceDraggableImageView : UIImageView { 
CGPoint startLocation; 
CGPoint startLocationInView;
EchiquierDisplayView *theSuperview;  
} 

@property (nonatomic, retain) EchiquierDisplayView *theSuperview;

-(void)correctDestinationPosition; 
-(void)initWithView:(EchiquierDisplayView *)aSuperview; 
...
-(void)askSuperview;
@end

@implementation pieceDraggableImageView

...
-(void)initWithView:(EchiquierDisplayView *)aSuperview
{
   theSuperview = aSuperview;
}
...
-(void) correctDestinationPosition
{
   [theSuperview correctIt];
}

이제 수퍼 뷰에서 기능 교정을 구현하십시오. 잘만되면 나는 당신의 질문을 올바르게 이해했습니다 ...

다른 팁

일반적으로 이것은 대의원을 통해 이루어집니다.

View Interface가 프로토콜과 일부 대의원에 대한 참조를 정의하도록하십시오. 그런 다음 Parent ViewController 가이 프로토콜을 구현하도록하십시오.

그런 다음 부모는 다음을 수행합니다.

someView.fooDelegate = self;

그러면보기는 다음과 같은 일을 할 것입니다.

if(self.fooDelegate != nil) {
   if([fooDelegate respondsToSelector:...]) {
      [fooDelegate performSelector:...];
   }
}

이것은 편집되지 않았지만 요점을 얻는 것 같습니다.

UIView는 해당 뷰 컨트롤러에 대한 지식이 없습니다.하나(또는 둘 이상)의 뷰 컨트롤러에 대한 참조를 유지하는 사용자 정의 UIView 하위 클래스를 생성해야 하지만 그렇게 하면 UIView와 UIViewController 사이에 추가 결합이 발생합니다.

뷰 컨트롤러에서 메서드를 구현하는 대신 슈퍼뷰나 뷰의 클래스에서 메서드를 구현하는 것을 고려해야 합니다.

다른 방법은 다음과 같습니다.

SuperviewsViewController *controller = self.superview.nextResponder;

if (controller && [controller isKindOfClass:[SuperviewsViewController class]])
{
    [controller method];
}

대부분의 경우 작동해야합니다.

Apple의 uiresponder 참조

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