Im having a problem with the UIView margins when Instantiating it on the callback function. When the view is instantiated like this it looks normal:
let viewController = UIStoryboard(name: "Tracking", bundle: nil).instantiateViewControllerWithIdentifier("tracking") as! CarrierTrackingVC
elDrawer.mainViewController = viewController
But when I instantiate in the api request callback like this, the view looks weird
TrackingController().getTruckTrack("7RZEY3VP") { (response, errs) in
if !self.requestErrors(errs) {
let truckTrack = TruckTrack(json:response["truck_track"].description)
let viewController = UIStoryboard(name: "Tracking", bundle: nil).instantiateViewControllerWithIdentifier("tracking") as! CarrierTrackingVC
elDrawer.mainViewController = viewController
}
}
I would like to know why that happen and any clue of how could I fix it. Thanks.
EDIT: This is the full code:
import Foundation
import UIKit
import KYDrawerController
import PKHUD
import JLToast
class MenuVC: UITableViewController {
@IBOutlet weak var fullnameLBL: UILabel!
@IBOutlet weak var profileTypeLBL: UILabel!
@IBOutlet weak var usernameLBL: UILabel!
@IBOutlet weak var profilePicIMG: RoundedImage!
@IBOutlet weak var homeLBL: UILabel!
@IBOutlet weak var servicesLBL: UILabel!
@IBOutlet weak var signOutLBL: UILabel!
@IBOutlet weak var trackingLBL: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
initContent()
NSUserDefaults.standardUserDefaults().addObserver(self, forKeyPath: PICTURE, options: NSKeyValueObservingOptions.New, context: nil)
NSUserDefaults.standardUserDefaults().addObserver(self, forKeyPath: NAME, options: NSKeyValueObservingOptions.New, context: nil)
if let url = SessionManager.sharedInstance.picture {
profilePicIMG.imageFromUrl(url)
}
}
override func observeValueForKeyPath(keyPath: String?, ofObject object: AnyObject?, change: [String : AnyObject]?, context: UnsafeMutablePointer<Void>) {
if keyPath == PICTURE {
if let url = object as? String {
profilePicIMG.imageFromUrl(url)
}
}
if keyPath == NAME {
usernameLBL.text = object as? String
}
}
deinit {
NSUserDefaults.standardUserDefaults().removeObserver(self, forKeyPath: PICTURE)
NSUserDefaults.standardUserDefaults().removeObserver(self, forKeyPath: NAME)
}
override func tableView(tableView: UITableView, didSelectRowAtIndexPath newIndexPath: NSIndexPath) {
self.tableView.deselectRowAtIndexPath(newIndexPath, animated: true)
let elDrawer = (self.navigationController?.parentViewController as! KYDrawerController)
switch newIndexPath.row {
//Profile info
case 0:
break
//Home
case 1:
elDrawer.mainViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("MainNavigation")
//Services
case 2:
elDrawer.mainViewController = UIStoryboard(name: "Services", bundle: nil).instantiateViewControllerWithIdentifier("services")
case 3:
TrackingController().getTruckTrack("7RZEY3VP") { (response, errs) in
if !self.requestErrors(errs) {
let truckTrack = TruckTrack(json:response["truck_track"].description)
let viewController = UIStoryboard(name: "Tracking", bundle: nil).instantiateViewControllerWithIdentifier("tracking") as! CarrierTrackingVC
viewController.truckTrack = truckTrack
elDrawer.mainViewController = viewController
}
}
/*let viewController = UIStoryboard(name: "Tracking", bundle: nil).instantiateViewControllerWithIdentifier("tracking") as! CarrierTrackingVC
viewController.truckTrack = TruckTrack()
elDrawer.mainViewController = viewController*/
default:
signnOut()
}
elDrawer.setDrawerState(.Closed, animated: true)
}
func signnOut() {
HUD.show(.LabeledProgress(title: NSLocalizedString("SIGNING_OUT", comment: ""), subtitle: nil))
UserController().signOut { (response, err) in
HUD.hide()
self.changeRootViewControllerWithIdentifier("start",storyboard: "Main")
}
}
func initContent() {
fullnameLBL.text = SessionManager.sharedInstance.userFullName
usernameLBL.text = SessionManager.sharedInstance.username
profileTypeLBL.text = SessionManager.sharedInstance.profileType
}
}
EDIT: viewController is a UITabBarController, each Tab contains a Navigation Controller and it's child is a View Controller.