1

I did the following: 1. Dragged UIView to place it in the ViewController ribbon Dragged UIView to place it in the ViewController ribbon

  1. Created a custom UIView class and added the outlets to the 'Edit Profile View' view fields:

import UIKit

class EditProfileView: UIView {

let globalDataHandler = GlobalDataHandler.sharedInstance

@IBOutlet weak var firstNameTextField: UITextField!
@IBOutlet weak var lastNameTextField: UITextField!
@IBOutlet weak var userNameTextField: UITextField!
@IBOutlet weak var passwordTextField: UITextField!
@IBOutlet weak var emailTextField: UITextField!
@IBAction func saveEditButton(sender: AnyObject) {
}
@IBAction func cancelEditButton(sender: AnyObject) {
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
override func drawRect(rect: CGRect) {
    // Drawing code
}
*/

}

  1. Gave 'EditProfileView' class as the Custom Class for the 'Edit Profile View' view in Storyboard.

  2. Created an object for 'EditProfileView' class in ProfileViewController and added the 'Edit Profile View' view to the main view upon clicking edit button in ProfileViewController.

class ProfileViewController: UIViewController {

let profileView = EditProfileView()

override func viewDidLoad() {
    super.viewDidLoad()
}

@IBAction func editProfileButton(sender: AnyObject) {
    profileView.firstNameTextField.text = "First Name"
    profileView.lastNameTextField.text = "Last Name"
    profileView.userNameTextField.text = "User Name"
    profileView.emailTextField.text = "Email"
    let testFrame : CGRect = CGRectMake(50,100,300,300)
    profileView.frame = testFrame
    self.view.addSubview(profileView)
}

}

But, the 'Edit Profile View' view doesn't appear on ProfileViewController. Please help.

Shashank
  • 31
  • 4
  • Why don't you just make `profileView` and IBOutlet of the view you dragged into the storyboard by selecting "Edit Profile View" in the document outline and control dragging into your `ProfileViewController`? Initializing it in code like `EditProfileView()` will not have the desired effect because there's overridden initializer that setups up your subviews. – beyowulf Jul 05 '16 at 17:02

1 Answers1

0

You have to link your UIView and your View (should be a distinct UIViewController) in the Xib.

profileView = storyboard.instantiateViewControllerWithIdentifier("ProfileViewController")

You must have an UIPresentationController for your ProfileVC

class ProfilePresentationController : UIPresentationController {
    override func frameOfPresentedViewInContainerView() -> CGRect {
        return CGRect(x: (presentingViewController.view.frame.width / 2.0) - 150.0, y: (presentingViewController.view.frame.height / 2.0) - 100.0, width: 300.0, height: 200.0)
    }
}

Your EditProfileView must implement the following delegate:

UIViewControllerTransitioningDelegate

the following properties of your profileView must also be set to:

profileView.modalPresentationStyle = UIModalPresentationStyle.Custom
profileView.transitioningDelegate = self

After that you can implement the delegate required method

func presentationControllerForPresentedViewController(presented: UIViewController, presentingViewController presenting: UIViewController, sourceViewController source: UIViewController) -> UIPresentationController? {
        return ProfilePresentationController(presentedViewController: presented, presentingViewController: presenting)
}
FouZ
  • 61
  • 7