In my application, i am using UIViewController and dynamically created UIView.In that view dynamically created subviews(UIButton and PickerViewController)..I want to display selected picker view value in a label control in UIViewController... How to add action to this button to move back to UIViewController...
views:
21answers:
1
Q:
How to add action to one dynamic button in one UIView Control to move back to UIViewController...
A:
You can either pass the reference of the UIViewCOntroller to the subview or you can create delegate methods for the subview.
Method 1 :
//below code is written in your UIViewController
/*You should write the implementation of initWithFrame:viewController: in 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];
}
Method 2 :
Make protocol and delegate in UIView and make the UIViewController to respond to the delegate calls
xCode
2010-08-05 04:31:23