How to controll second UIView (subview) from a different UIViewController file in one XIB
I am strugling on the following task.
I am trying to control my subview from another viewController class. What I did and does not work is this.
I inserted an obj开发者_开发问答ect and changed it class to my second viewController class. Then I connected its UIButton outlet to a button I have on my subview. I then connected the buttons action to the outlet of my second view controller.
What I get when I run is this. It all shows up well but when I try to touch the button that resides in my subview app crashes. I am only left with a worringing: "Action unavailable: The "Touch Up Inside" event of "Rounded Rect Button".
It's probably my logic that is incorrect. Thanks for help.
Well after a long research I got an answer to my problem. As it appears I was doing everything right.
The problem is that after the initial XIB file is initialized it autoreleases all views and subviews. So to prevent from gettig your second view controller from being released implement this method
- (void)awakeFromNib {
[self retain];
}
in your view controller .m file. This method will retain your second view controller alive and allow it to recive and respond to UI actions.
精彩评论