Situation: In the main View Controller, I have a UIScrollView and within that I have a UIView all working fine (View Controller > UIScrollView > UIView).
//In the main view controller...
- (void)viewDidLoad {
UIView *subview1 = [[UIView alloc] initWithFrame:rect1]; //create a UIView
[self.scrollView addSubview:subview1]; //add it to UIScrollView
}
Question: How can I pass a string from that UIView back to my Main View Controller?
Common solution is delegation. You create a custom
UIViewsubclass that knows how to report the information to whoever is interested:If you want to, you can create a protocol for the delegate, so that the compiler can check more things for you. Note that the delegate is an assigned property, not retained, because retained property would lead to a retain cycle.
The problem can also be solved using notifications, KVO or blocks.