I'm building an app which has 4 screens, on the second screen the user will set time by date-picker on tableview.
There are few times to be set (depending on array.count).
On the third screen the user will set the location, and on the 4th screen user will see info from API and the time has been set by the user, also on tableview cells.
In case the user wants to change or update the time he set in one of the cells to different time, I need to be able to go back to the second view with all the input user added already remain, and the user can change only the cells they want to change, without adding all the time all over again.
When I'm using segue it creates a new 2nd vc and all the previous info erased.
I thing you have to use delegate to propagate this information from whichever screen to which ever screen you want. In Order to achieve that you have to loose the segue.
https://medium.com/#nimjea/delegation-pattern-in-swift-4-2-f6aca61f4bf5
In this link Delegation pattern is explained very well. Please refer that.
Related
i would like to ask if there is any ways we can reset our view in UIPageViewController implementation. For example I have two views,
in View A, there is a button which changed text upon clicking as well as a tableview. Once i have clicked the button or when i have scrolled to the middle in my tableview, when i have swiped to View B, my states in View A will not be reset when I go back to View A where the button's text are not reset and my tableview is in the middle where from where I scrolled earlier.
Is there any ways once we move pages between UIPageViewController, the pages reset their states?
The answer is "It's kind of complicated."
The background:
If you only have 2 pages in your page view controller the page view controller will probably keep strong references to both, and so they will retain their state as you page back and forth between them.
If you have more than 2 pages, and are not showing 2 pages at the same time and using a center spine, the pages that are not either currently visible or next to be displayed will likely get released and you will then recreate them when the user displays them. In that case the pages won't remember their state unless you do extra work so that they save their state when they are moved off-screen.
Your case:
You always want your pages to reset when the user swipes to a different page and then back again.
I'd suggest you write your pages' view controllers logic so they respond to viewWillAppear(animated:) by resetting themselves to their starting state. (scrolling table views to the top, resetting button states, or whatever.)
Ideally, you might want to make that an option that is controlled by a flag (resetsOnAppear: Bool). That way if you later decide you don't want that to happen, you can just set the flag to false and don't have to refactor your code.
Is there a way to know in code when user has closed a modal by tapping the title? Apple's documentation states:
The title of the modal interface is set to the string Cancel unless the presented interface controller explicitly changes it using the setTitle: method. Tapping the title dismisses the interface automatically.
As far as I know there is now way to replace that title with a button.
I could fire a notification on didDeactivate() or willDisappear() but these will also be called when app enters background. So I could do an additional check in ExtensionDelegate's applicationWillResignActive() to differentiate between user's action in my app or outside my app but this seems very fragile.
Are there any better ways?
Why would one need this?
In my case I have an initial screen where a user makes a choice. After the choice is made I present screens that contain data based on that choice.
I always want to show the data when the choice has been made. So I save the choice and present the modal on app launch when it is present.
But I don't want to show the data if the user has closed the data display. Yet I still want to display the choice made on the first screen. So I can't use the fact that the choice has been made to trigger modal displaying.
Hence I need to know if the modal has dissapeared because of user interaction in app or because the app got switched away.
Unfortunately, there is no other way to do so.
But why do you need to add additional checks at applicationWillResignActive()? I think there is no need to do so.
I'm working on my first app and I've issues on how to layout some of its logics.
Basically, what the app is supposed to do is to show a first screen when launched where user can fill in some values and press a button that opens a tableview which shows results. The first screen (view), outlets and connections are all working fine. The issue I'm having is how to leave this "home" search view and show the results to the end user on a table view. Right now, I've only 1 view with its related View Controler and this controller handles the tasks of taking user inputs and get results throughout a HTTP post request.
I need your guidance...Thx in advance
Stephane
Is there a reason that this all has to happen on one screen? iOS is set up to allow for this to happen very easily and (I think) attractively by using a UINavigationController and pushing in a new view controller (could be a UITableViewController or simply a UIViewController that contains a UITableView).
If you MUST have all of this take place in one view, Swastik is correct that it will require some view acrobatics. One way to do it attractively is to use the UIView animations introduced with iOS 4.
Here's Apple's UIView documentation: UIView Class Reference
Specifically, check out the CLASS methods of:
1. animateWithDuration:animations: (with or without completion:)
2. transitionWithView:duration:options:animations:completion:
Note that these methods will require you to learn a little bit about blocks, but it's worth it and I think blocks give tremendous power!
With the methods mentioned above, you could fade out your form and fade in your tableview, or maybe just move the form off-screen while the table view flies in. The possibilities are limited only by your imagination.
u can add a table in ur xib.Initially make it hidden, & when u need to show it unhide it & also if u want to update table's data , you can reload the data of the table.
I want to put an ad on my iPhone application.
And I'm using TabBar to separate some features.
Here's my question. I just want to put ONE AD which always should be displayed no matter what user select & switch between views by pressing tab-bar. I want that ad right above the tab-bar.
I don't want to put ad on every view nor refreshed every time user changes view.
Can somebody give me some idea??
thanks.
Your TabBarControllers view was added to the application window at some point. This is usually in your applicationDidFinishLaunching method if doing it by code, otherwise it is done through Interface Builder. Either way, if you want to add a view globally, do it at the end of applicationDidFinishLaunching and add it as a subview of the application window, not to any individual view controller. Just ensure you are adding it after the tab bar controller as otherwise it will be covered up.
When my app receives a Push Notification, application:didReceiveRemoteNotification: receives the data. When the user open the app from a notification, I want to jump to the last UITableView in the stack, to display the 'details' related to the Push Notification.
I am able to jump to the correct tab in the UITabBar.
Is there a way to Push views in that Tab from the App Delegate, or am I going about this the wrong way?
If you're already able to jump to the correct tab, you're almost there.
One way to do it would be to save off the push alert information into nsuserdefault... maybe in a form of a dictionary object in the "didReceiveRemoteNotification". It's like of like save off a cookie web development for later use.
Then for the viewcontroller you're displaying in the tab that you jump to, you could do a check in viewWillAppear and see if you have anything stored in your nsuserdefault and grab the saved off notification data there and you can look up the corresponding data in your UITableViewDataSource.
Once you have that, you can call or do what ever you'd normally do had you selected the same data/object represented by a table cell and push the desired view (controller) into view.
Make sure to remove the object saved in NSUserDefault once you're attempted to push the view.