revealViewController() always returns nil
The most convenient to be a reason for the revealViewController
to be nil
is you didn't connect segues
correctly in stroyboard
.
See this tutorial it's quite easy to follow.
Update
If in your case you just need to open a login vc if the user is not logged in you may do like this:
in AppDelegate
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
var rootVCStoryboardId = userIsLoggedin ? "SWRevealViewController" : "LoginViewController"
self.window?.rootViewController = UIStoryboard(name: Storyboards.main, bundle: NSBundle.mainBundle()).instantiateViewControllerWithIdentifier(rootVCStoryboardId)
Where SWRevealViewController
is the stroyboard id for SWRevealViewController and LoginViewController
is the storyboard id for your login view controller(or its navigation controller if exists).
SWRevealViewController push to actual navigation controller
Here's your solution
From Menu to Normal ViewController by using Swrevealviewcontroller "setFrontViewPosition"
In Swift
let obj = self.storyboard?.instantiateViewControllerWithIdentifier("ViewController") as! ViewController
let navController = UINavigationController(rootViewController: obj)
navController.setViewControllers([obj], animated:true)
self.revealViewController().setFrontViewController(navController, animated: true)
self.revealViewController().setFrontViewPosition(FrontViewPosition.Left, animated: true)
In Objectctive-c
-(void)main{
LoginViewController *tar = [self.storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:tar];
[navController setViewControllers: @[tar] animated: YES];
[self.revealViewController setFrontViewController:navController];
[self.revealViewController setFrontViewPosition: FrontViewPositionLeft animated: YES];
}
CLGeocoder always returns nil for latitude / longitude
It's not nil you return a value from an asynchnous method you should use a completion
func getLocation(address: String,completion:@escaping(CLLocation? -> ())) {
let geocoder = CLGeocoder()
geocoder.geocodeAddressString(address) { placemarks, error in
guard let placemark = placemarks?.first else { return }
completion(placemark.location)
}
}
Call
getLocation(address: address) { loc in
// embed all code here
}
Delegate always nil in tableviewcontroller
You've declared your delegate (TableViewDelegate) as non-optional, but in the didSelect
method, you're using optional chaining - self.delegate?.clickedTableViewCell(info: currentItem!)
Declare your delegate as weak optional property - weak var delegate: TableViewDelegate? = nil
to avoid retain cycle.
Delete your profilePlaceTableViewController.delegate = self
. You're doing the same in your performSegue
method.
And change your protocol declaration to:
protocol TableViewDelegate: class {
func clickedTableViewCell(info: String)
}
BannerView Nil when calling function from another class
I used Notifications to finally work this out... Controller 2 sends a notification that a purchase has been made, and Controller 1 observes and waits for this notification, then takes care of hiding the banner in Controller 1.
https://blog.bobthedeveloper.io/pass-data-with-nsnotification-in-swift-3-73743723c84b
Picker result is always nil
Here it is
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
if let url = info[UIImagePickerController.InfoKey.mediaURL] as? URL {
self.url = url
}
isShown = false
}
Related Topics
Url Opening Swift App - Open Works - Called Function Does Not Work
iOS Add Button to Widget Extension
Can't Write Non Current User Objects by Pfuser Currentuser
Adding an Skscene to a Uiviewcontroller
Uitableviewcells Initial Load View/Display Issue
Cocos2D Sprite Repeat Animation Forever
iOS How to Get a List of Already Purchased Products
Prepareforsegue Not Called from Custom UItableviewcell
Fastlane Boarding with Two-Factor Authentication
Why [Uiscreen Mainscreen].Bounds] Is Not Returning Full Screen Size
Use Elcimagepickercontroller to Pick Video
Googlemap API Gives Wrong Coordinates for Direction Between Two Points
Box Shadow Spread Bug in Webkit in iOS 7 on Retina Ipads
Removing Parentheses from The String in iOS
How to Get Nsnumberformatter Currency Style from Isocurrencycodes