Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialIgor Shvetsov
5,716 PointsThere's an error
When I run my app with not logged in user performs "showLogin" seque and I see LoginViewController. If i would try to swipe from left side to right (it is the same as back button in NavigationController) navigation controller would try to pop the previous view controller and then error happens. Error without description. I can't understand why it happens. It seems to me that the InboxViewController should appear.
6 Answers
Rasmus Rønholt
Courses Plus Student 17,358 PointsIt's been a while since I did this course, so I don't remember how the login screen segue was implemented. But it would seem that you shouldn't be able to go to the inbox at all if not logged in. If your navigation controller is trying to pop the login screen without being logged in, then something is wrong.
Igor Shvetsov
5,716 PointsLogin screen isn't modal. There's a push-segue. The previous course where I build Ribbit app was upon iOs 6. There was no such gesture (swipe for pop previous view controller). So we just hided back button. There's an logical problem. I think we must check logged in user or not in AppDelegate instead of ViewController. But there's another question. Why app crashes when trying to display InboxViewController with not logged in user.
Igor Shvetsov
5,716 PointsI've found out what is the error. I have checking for logged in user in viewDidLoad method of InboxViewController. I must replace it to the viewWillAppear
Igor Shvetsov
5,716 PointsIn the viewDidAppear of InboxViewController we try to perform PFQuery using currentUser which is null. So app crashes.
Rasmus Rønholt
Courses Plus Student 17,358 PointsAhh - ok... so do something like
if currentUser != nil {
//do query stuff
} else {
//tell the user to log in
}
I really would still suggest that you present the view modally though.
Rasmus Rønholt
Courses Plus Student 17,358 PointsOk... if the user is not supposed to be able to "go back" from the login view without login in, then that view really should be presented modally. There are a couple of ways you can prevent the navigation controller from responding to the swipe, but the implementation changes between versions of iOS, and apparently doing so is cause for rejection at the app store.
So - present the view modally :)
Igor Shvetsov
5,716 PointsThank you, Rasmus!
Rasmus Rønholt
Courses Plus Student 17,358 PointsAny time :)
Rasmus Rønholt
Courses Plus Student 17,358 PointsRasmus Rønholt
Courses Plus Student 17,358 PointsIs the login screen presented modally