2012-09-11 5 views
1

안녕하세요, iOS에 익숙하지 않습니다.다른 클래스의 수퍼바이저에 대한 하위보기 만들기가 작동하지 않습니다.

나는 2 개의 클래스가 있는데 하나는 부모 클래스이고 다른 하나는 자식 클래스입니다. 부모 클래스에서 UIScrollView를 만드는 메서드가 하나 있습니다. 부모 클래스의 개체를 만들어 하위 클래스에서 해당 부모 클래스 메서드를 호출하려고합니다. 자식 클래스에서 호출 할 때 해당 메서드가 호출되지만 자체 메서드를 사용하여 부모 클래스에서 동일한 메서드를 호출하면 UIScrollView가 만들어지지 않습니다.

어디에 문제가 있는지 알 수 없습니다. 부모 클래스 나에게

//있는 ScrollView 생성 방법을 안내하시기 바랍니다 //

-(void)creatingScroll 
{ 
UIScrollView * propertyScrl = [[UIScrollView alloc]initWithFrame:CGRectMake(10, 200, 320, 160)]; 
propertyScrl.scrollEnabled = YES; 
propertyScrl.showsHorizontalScrollIndicator = YES; 
propertyScrl.contentSize = CGSizeMake(600, 60); 
propertyScrl.backgroundColor = [UIColor redColor]; 
[self.view addSubview:propertyScrl]; 

} 

// 자식 클래스의 방법 위의 호출 유 ParentViewController의 또 다른 객체를 생성 및 호출 //

ParentViewController *vc = [[ParentViewController alloc]init]; 

    [vc creatingScroll]; 

답변

1

creatingScroll 해당 개체에 대한 메서드는 viewController에 푸시 된 뷰가 아닙니다.

U는 프로토콜 & 대리자를 사용하여 부모 클래스 메서드를 호출 할 수 있습니다.

참조하십시오 http://mobiledevelopertips.com/objective-c/the-basics-of-protocols-and-delegates.html

는 도움이되기를 바랍니다. 행복한 코딩 :)

+0

답변 해 주셔서 감사합니다. – thavasidurai

+0

잘 작동합니다. 당신의 도움을 주셔서 감사합니다. – thavasidurai

0

subclasssuperclass의 모든 메소드를 상속 했으므로 서브 클래스에서 [self creatingScroll]으로 전화하면됩니다.

+0

답변 해 주셔서 감사합니다. 그러나 subclass는 이미 다른 수퍼 클래스에서 상속되었습니다. – thavasidurai

0
  -(UIScrollView *)creatingScroll 
{ 
UIScrollView * propertyScrl = [[UIScrollView alloc]initWithFrame:CGRectMake(10, 200, 320, 160)]; 
propertyScrl.scrollEnabled = YES; 
propertyScrl.showsHorizontalScrollIndicator = YES; 
propertyScrl.contentSize = CGSizeMake(600, 60); 
propertyScrl.backgroundColor = [UIColor redColor]; 
//[self.view addSubview:propertyScrl]; // don't add here 

return propertyScrl; 

} 

//calling above method from child class or any class// 
probably in viewDidLoad of child class 

ParentViewController * vc = [[ParentViewController alloc]init]; 

  UIScrollView * scrollView = (UIScrollVIew *) [vc creatingScroll]; 

    [self.view addSubView:scrollView]; 
관련 문제