2010-08-05 72 views

回答

0

您可以將UIViewCOntroller的引用傳遞給子視圖,也可以創建委託方法爲子視圖。

方法1:

//下面的代碼寫在UIViewController

/*你應該寫initWithFrame實施:的viewController:在UIView的

CustomUIView *youSubView = [[CustomUIView alloc]initWithFrame : yourFrame viewController:self]; 

//below code is in CustomUIView 

- (id) initWithFrame :(CGRect)frame viewController:(id)vc 
{ 
.... 
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom]; 
[btn addTarget:vc action:methodinVc forControlEvents:UIControlEventTouchUpInside]; 

} 

方法2:

在UIView中創建協議和委託,並使UIViewController響應委託調用

相關問題