closing out modal view completely ios - ios

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

Related

Complex Startup Logic in iOS Apps: Where Should it Reside?

Everyone has seen the classic didFinishLaunchingMethod run amok.
Well now that we have additional things to consult when starting up like CloudKit, that are, to make things worse, asynchronous, the app delegate seems like the wrong place to do even the most basic stuff like asking if they have accounts and establishing syncing, or grabbing a snapshot.
I hate the idea that those things would go into the first controller that the app would launch, flashes me back to 4GL tinkertoys from days of yore.
Yet, we have to honor the flows of the storyboards. I have found nothing searching around on this. And sadly the most extensive Apple example, Lister, is not a great source for best practices.
It's suitable for the app delegate to trigger the start of this work, but not to handle the results. Often you want some way to display progress / errors / request user info. So, having some form of 'splash' view controller which handles the transition from your launch image into this process and controls the flow into the main app is handy. Generally the logic for this kind of thing is reusable in other situations so that part should be in some other controller class. The storyboard can make the splash VC the initial controller and the app delegate can create and pass it the data controller class which deals with the logic and updates the VC (it's delegate) with the results. Often the splash VC will then pass the data controller on to the subsequent VC it displays, though that isn't required of course.

ScrollView and viewcontrollers

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!

Showing loading screen in Ruby on Rails

I have one part of my site which takes a long time to load. This makes the site appear to hang when you click a link to this. I know it will happen and so it's fairly mean to not tell the user that they are waiting for something which is meant to happen. What I'm wondering is if there is a way to render some kind of loading screen with a simple loading spinner animation to show the user that the server is working. I was thinking of creating a new view which would automatically redirect to the actual view but I thought this would be a bit messy. Any better ways?

Direct to appropriate ViewController when user logs out/ is not logged in

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!

can my app delegate be used as a controller of UIViewControllers (MVC)

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.

Resources