I posted a similar question some time back, but it turns out the solution I chose is not sustainable nor a good one. So I'm trying again, with a different approach.
Here's my problem
I'm making an app that uses Facebook login and connects to a server. Therefore, at any given time, the user has to be logged in with Facebook and the user_id needs to be stored in the NSUserDefaults. If at any time in the app, any of the two is not present, I need to direct the user to a log-in screen.
In the same fashion, if the user manually presses log out, I need to direct him/ her to that same screen.
Seing that I'm using the SWRevealViewController, I need more than one UINavigationController. Therefore the popViewController does not work.
Here's my app setup
The initialViewController is a UINavigationController, pointing to another ViewController. In here, I check if the user is signed into Facebook and that the user_id is stored in the NSUserDefaults. If they are, I direct them to the SWRevealViewController. If they are not, I direct them to a LoginViewController (I use performSegueWithIdentifier:). From the LoginViewController, after the user is successfully signed into both Facebook and my servers, I direct them to the same SWRevealViewController.
Basically, the SWRevealViewController splits into two: A sw_front and a sw_rear (the menu). Each of those requires their own UINavigationController (as far as I know, I didn't get it to work without).
From here on, the app splits into several different ViewControllers.
You can see the storyboard in this image:
(Link to full-res image here)
(The logout button is the blue one on the top, the login is the blue one at the start)
Here's what I've tried:
The last time I asked a similar question, I chose to go with a solution where I present the InitialNavigationController using the presentViewController function when the user logs out. This seemed to work fine, and the new ViewController was presented modally which other apps seem to do as well (see linkedIn and more).
However, when I proceeded to log in again, the Facebook showLoggedInUser method seemed to be called twice (I placed a NSLog() statement in there). When I repeated a third time, it ran three times. Fourth login, four times, and so on.
In addition, on the second logout, I would get a warning in the compiler saying Warning: Attempt to present <UINavigationController: 0x13c566730> on <UINavigationController: 0x13c549c70> whose view is not in the window hierarchy!. This warning would also keep incrementing as I repeated the login-logout process.
What I want:
As I understand, I keep adding the InitialViewController to the stack as a modal view, and this is not what I want. I simply want to go back to the start. Or anything that works for that matter. Just as long as I have a simple login/ logout system that works, I'll be glad. Bear in mind that we need to be able to call the View that should be presented from any view in the app if the user appears to be logged out (if he logged out from Facebook, if the Facebook thing timed out, or if the NSUserDefaults for some reason reset (for example under an update)).
If possible, I'd like to know what other apps does to achieve this (for example linkedIn, Facebook, Twitter, or anyone else).
What I've been thinking about is adding a separate LoginView not connected to anything, that I can load up modally whenever I see the user is logged out. Whenever the login is completed, I simply dismiss the view and the user returns to where he was last.
The only problem I see about this is that when the user logs out, he is technically still "inside" the app, though he cannot dismiss the modal view controller without logging in.
Would this be a bearable solution to my problem?
What do you suggest?
Some physical code showing how to present the new view/ going back (or any other solution) is preferred, but any help is appreciated!
I know this was a long question, and there are possibly many answers, but I've been stuck at this for way to long and I just want a solution that will work with my setup. So I felt the need to explain everything. If there's anything you don't get, please don't hesitate to ask!
Thank you so much in advance!
Related
I building an app with user profiles. When a user searches for another user or searches their own followers I of course want to display said user profiles. My question is how should I best set up clicking on user profiles within user profiles while being able to handle the potentially infinite stack of profiles.
Example, user searches for a friends and then looks thru the friends of the friend and then keeps searching and keeps clicking. I then want the user to be able to back track like in the FB app.
The two options I've thought about are making UIViews within UIViews or more Viewcontrollers. If anyone has experience with this particular issue or github links to projects that address this issue that'd be amazing thanks!
Also I can post code from my project if anyone would think it'd be helpful but I don't see how it would be at the moment.
In general you would just use a regular UINavigationController and let the user navigate normally, continually pushing new view controllers onto the stack. You shouldn't really have to worry about performance in the view controllers underneath the top one, unless maybe they are doing something expensive repeatedly (in which case, you would disable those expensive operations in something like viewDidDisappear: and re-enable them in viewDidAppear:).
The number of view controllers would have to be pretty high for this to cause issues under normal conditions.
Here is context for my question, this is an optional read:
I have to develop an app for a
school project. At the end of the year some people I don't know will
listen to me presenting my app, and review my presentation and my app
(note that they will probably not be app developers, they are usually
IT professors) (note also that I'm allowed to ask for help to anybody,
and I can use internet since I do this mostly on my "free time")
So since October I'm developing my app, that takes a lot of time
because this is my first app. And here comes the issue:
My app is a giant Scroll view with 5 NavigationsControllers, each containing a ViewController. These ViewControllers sometimes have buttons that leads to an other ViewController. The problem is when I use these buttons, and another view controller is displayed, when I swipe right or left the ScrollView scrolls and another ViewController from the scrollView is displayed. I don't want this to happen because most of the time the ViewController displayed after the tap on a button is not meant to stay, it's generally a form to send data to the server.
As I think this is difficult to understand, you can download the project on Github
Is there a way for me to disable scroll on chosen ViewControllers? or should I change everything to avoid using a ScrollView?
Bonus question:
Is it a really really bad idea to make an app this way, or did I just miss something?
Thanks for your help!
I have a messaging system, theres a inbox view and a viewmessage view, if i go back to the inbox im still reciving data from that message, and if i load another conversation between me ad another user its still loading the previous conversation data i had (verified by logging the convo's, and the new one i have open, and its a continuous loop so to say... basically im trying to figure out how to totally close out a view... i seen dissmissViewController and used that, but all it does is visually make the view go away... it doesn't truly close it.. whats the method to call to do what im trying to achieve?
These are all modal views, my app uses no navigation views due to the nature of the app
edit: i found some great documentation that im going to look over hopefully i'll get my answer from there.
Using Delegation to Communicate with Other Controllers
I'm trying to build a universal iOS app. So, in Xcode I started with a Master-Detail template.
In the iPhone version of this, my first view is a list of items, and I have a "Logout" button in my Navigation Bar. When the user launches for the first time, a view-controller is presented, modally, on top of my normal "master" view. It just asks for a user/pass, lets the user log in. If the user hits the "Logout" button, some cleanup occurs, and then they are presented with the Login screen again.
On the iPad side of things, I'd like to have a UISplitViewController - as that interface matches well with what I'm trying to do. I'd like to do this in a similar fashion -- present the user with Login the first time they launch. Then later on, if they decide to leave the app, they can hit Logout, and be presented with Login options again.
I'd prefer to cover the entire screen with one view (just user/pass/login button), but am having trouble figuring that out, especially if the "master" view is visible.
So, the question is this: what is the preferred way to show a login screen, with a UISplitViewController in the mix, so that the user can't do anything else but login?
This really sounds like a personal choice/design decision.
You could have the "master" view be the login screen and have the "detail" be just a splash screen or cute kitten photo that says "please login"
You could also have a single UIView be the "initial" view page and have that segue into the splitview
I think you're quite open in the "how" of it so perhaps I'm not quite understanding your question.
Can an app delegate act the as the glue between all my UIViewControllers for the whole app?
I'm creating a mail client that has a navigation structure very much like sparrow (and fb etc). The first screen would be a login screen.. which would then lead to a UITableViewController that has the famous left menu button, which if clicked reveales other VC's underneath.
To make a long story short, right now it's my app delegate that's running the show.. it's the one that decides if to show the login screen if on first visit, or the default mailbox along with its subviews. If I get information from one subview, it hands off that info to the app delegate, which in turn passes it on to other view controllers.
Is this right from an MVC point of view? I know an app delegate is the first point of contact, it's what kicks off the application, but I haven't seen it used this extensively. I just want to make sure if I'm following iOS MVC best practices here.
It's not recommended, but it's perfectly legal to do that. I generally use a master view controller class and do most of the heavy lifting in that. Keep in mind that XCode will dump most of the auto generated code in the app delegate if you are using Core Data, so it can get a little difficult to navigate if you are using Core Data. It's really just a personal preference though. If it were me, I would still have the app delegate do the login screen vs. main screen logic, but put most of the app logic in a main screen controller.