开发者

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 acc开发者_如何学Cepting 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)
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜