UIScrollView adding UIViewController as a sub view

2019-05-10 16:06发布

问题:

I am currently working on my application and would like to have a UIScrollView and UIPageControl which would allow the user to swipe the screen left and right to get to different view controllers.

I have this working so far, so that I can swipe left and right to see either view controller however I am finding that when one of my UIViewControllers needs to access it delegate nothing happens, for example UITableViewDelegate.

This is the code i have so far in my scrollViewController

 CGRect frame2;
frame2.origin.x = self.scrollView.frame.size.width * 1;
frame2.origin.y =30;
frame2.size = self.scrollView.frame.size;
myViewController *vc3 = [[myViewController alloc] initWithNibName:@"myViewController" bundle:nil];
vc3.view.frame = frame2; 

[self.scrollView addSubview:vc3.view]; 
self.scrollView.contentSize = CGSizeMake(self.scrollView.frame.size.width * 2, self.scrollView.frame.size.height);

One thing I am not able to do also is release [vc3 release]; after adding it to the scrollView the app will just crash.

Any help would be great, also please let me know if I am going about this the wrong way.

Thanks Aaron

回答1:

By adding v3.view , v3's retain count wont increase. So you cant release v3. you can
[v3.view release];