2013-01-09 40 views
1

我的應用程序的每一個的UIViewController管理iboutlets使用的UITextField的代表,如:在基本視圖控制器

- (void)textFieldDidBeginEditing:(UITextField*)textField { 

    self.responder = textField; 

} 

- (BOOL)textFieldShouldReturn:(UITextField*)textField { 

double elementYPosition = self.responder.frame.origin.y; 
double elementHeight = self.responder.frame.size.height; 
double scrollYPosition = self.scrollView.contentOffset.y; 
/* some logic */ 

} 

現在我試圖創建基礎視圖控制器,這樣我就可以圍繞繼承使用它,重用這些方法。在基本視圖控制器responder物業工作得很好,因爲委託的UITextField設置它的值,但滾動型是一個IBOutlet中,我真的不知道如何設計這個基類:

#import "ViewControllerBase.h" 

@interface ViewControllerBase() 

@property (weak, nonatomic) UIView* responder; 
@property (weak, nonatomic) IBOutlet UIScrollView *scrollView; /* ??? */ 

@end 

@implementation ViewControllerBase 

-- methods 

@end 

回答

0

在子標題:

@property (weak, nonatomic) UIScrollView *scrollView; 

在子類加載方法:

self.scrollView = (UIScrollView *)self.view.subviews[0]; 

但它只能因爲我的視圖控制器總是在以下備考t:

UIViewController (self) 
    UIView (self.view) 
    UIScrollView (self.view.subviews[0]) 
     UILabel 
     UIElement 
    UIElement 
    UIElement 
相關問題