简体   繁体   English

UIScrollView 添加 UIViewController 作为子视图? 使用 UIPageControl

[英]UIScrollView adding UIViewController as a sub view? with UIPageControl

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.我目前正在开发我的应用程序,并希望有一个 UIScrollView 和 UIPageControl 允许用户左右滑动屏幕以访问不同的视图控制器。

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.到目前为止,我已经完成了这项工作,因此我可以左右滑动以查看任一视图 controller 但是我发现当我的 UIViewControllers 之一需要访问它时,委托没有任何反应,例如 UITableViewDelegate。

This is the code i have so far in my scrollViewController这是到目前为止我在 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];我也不能做的一件事是发布 [vc3 发布]; after adding it to the scrollView the app will just crash.将其添加到 scrollView 后,应用程序将崩溃。

Any help would be great, also please let me know if I am going about this the wrong way.任何帮助都会很棒,如果我以错误的方式解决这个问题,请告诉我。

Thanks Aaron谢谢亚伦

By adding v3.view, v3's retain count wont increase.通过添加 v3.view,v3 的保留计数不会增加。 So you cant release v3.所以你不能发布 v3。 you can你可以
[v3.view release];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM