简体   繁体   中英

How to add a UIViewController view on UIScrollView

I have a small problem in loading the UIViewController on scroll view.

In my application, I am using 4 tab buttons at the bottom. One of which contains a scroll view, as number of fields in that view are more. One of the field is for accepting the date from the user.

When I am adding this Date Picker View(UIViewController) on UIViewController class, there is no problem in loading the Date Picker View, but when I am adding Date Picker View on UIScrollView there is problem. Application crashes when I am touching any button on Date Picker View.

Is there any problem in loading the UIViewController on UIScrollView ???. What is the alternative if I want to accept the date form user on scroll view or how can I add the UIViewController on scroll view to accept the date from Date picker.

Thanks in Advance. Regards, VIshal.

Try this and see:

self.scrollView.frame = CGRect( <set frame> )

var vcView = UIView(frame: CGRect( <set frame> ))
addChildVC(vcView: vcView)

self.scrollView.addSubview(vcView)
self.scrollView.contentSize = CGSize( <set content size> )

Add child view Controller

func addChildVC(vcView: UIView){

let testVC = self.storyboard?.instantiateViewControllerWithIdentifier("testIdentifier") as! TestViewController
    testVC.view.frame = vcView.bounds
    vcView.addSubview(testVC.view)
    self.addChildViewController(testVC)
    testVC.didMoveToParentViewController(self)
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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