Why popover segue taking lot of time for the First time? - ios

I've an application where one HomeViewController triggers the popover segue so that destinationView controller may appear as a popover View controller. Everything is fine and destinationView Controllers is opening as popover View controller.
But the problem is when I First touch the button, its taking lot of time to open destinationViewController. and later after that second touch onwards on its opening faster just on touch. why so ?

The answer mostly lies in your code itself.
My guess is you are making some network call or data processing on main thread making UI responsiveness hit. You are probably caching the massaged data and using it second tap onwards.
You can fix this by putting break point and understanding the implementation line by line.

Related

Restore view state without animating segue

I have added state restoration to my app, and it seems to work fine, however I'm not happy with the way that it functions.
Basically, the app is a Disney wait time tracker, so it has a selection of the four parks when you first open the app. Tapping on one of these parks segues (with the slide up animation) to the main section of the app. The problem is - When the app is reopened and the view restores after a few seconds, the slide up segue is performed (which is quite distracting).
Anyone have any idea why that is happening?
It might be down to how you are triggering your view and what time of segue you are choosing.
Otherwise you can specify whether its animated in your segue method:
ObjectiveC
[self.navigationController pushViewController:aYourViewController animated:NO]
or in Swift:
self.navigationController?.pushViewController(yourController, animated: false)

Swift: Memory not clearing when I segue to another view controller, recieving memory warning

I am building an application in Xcode 6.2, for iOS 8.1. I have a UIViewController (LevelViewController) which contains a UICollectionView whose cells each represent a level in my game (each one has a label w/ a number). Once one of the cells is selected I perform a show segue to an SKScene which loads all the data for that particular level.I also have a "menu" button which performs a show segue back to the main menu.
Functionally this all works, however I am having serious memory problems after performing both segues. After peeking in instruments it appears that when I segue out of the LevelViewController that all of the UILabel that I added for each individual UICollectionViewCell remain in memory, along with everything else contained in the cells. There should only be 192 labels (for 192 levels) but after performing this segue several times they add up to around 1000 in instruments.
Obviously these are not being deallocated in memory, It's my understanding that swift should take care of that, so i'm not sure what the problem is. I should also note that the UICollectionView was added programmatically, and no IBOutlets are used.
So how exactly can I get rid of those labels, and really, the UICollectionView itself when I segue away from the LevelViewController. Im seriously confused about this and it's ruining my St. Patricks Day. So for the love of all things Irish please help a lad out :)
Note: methods I have tried
self.collectionView.removeFromSuperView()
self.collectionView = nil
self.collectionView.deleteItemsAtIndexPaths(path)
It's hard to tell without seeing the code you're using to perform these segues. But I'm guessing that the problem has to do with how you are segueing between the view controllers.
I also have a "menu" button which performs a show segue back to the main menu.
If I had to guess based on your language above, instead of popping the Level ViewController (I'm assuming it is embedded in a UINavigationController), you are trying to segue back to the main menu using performSegueWithIdentifier: This will actually create a new instance of the view controller and push it onto the navigation stack (and retain the existing instance of it leading to your memory woes).
If that's indeed your problem, the solution is pretty simple: When your menu button is tapped, you should be calling popViewControllerAnimated or dismissViewControllerAnimated:completion:.
A simple little thing worth doing while you get accustomed to iOS segueing is to add de-initializers to all your view controllers as follows so as to get ongoing debug messages that objects are being deallocated as expected:
deinit {
debugPrintln("Name_of_view_controlled deinitialized...")
}
Happy St. Paddy's Day!

iOS: Switching between views quickly causes data being passed to be incorrect

In my iOS app, I have made it so that when I segue from the main view to a second view data is passed, and then when I go back to the main view, data is passed back to it (using a protocol). This works fine if I segue between views slowly, but once I start doing it quickly, (spamming "push" and "back" buttons) the data becomes wrong. I use the prepareForSegue,viewWillAppear and viewWillDisappear methods to transfer data.
If anyone else has had a similar problem and can point me in the right direction that would be great.
Thanks!

Memory management of view while using NavigationController

I changed navigation in my application from using UITabBarController to u UINavigationController. I.e. former solution (1st version) was based only on the TabBarController - 4 ViewControllers (one simple TableView, one simple custom view and one MapView with many overlays). The second version is based only on the UINavigationController.
In case of TabBarController it was clear and simple, everything worked fine, especially MapView. I mean: the MapView was loaded once (with a significant number of overlays) and when I went to another view and back to the MapView the MapView was still there with its overlays already loaded and displayed (simple check: MapView`s viewDidLoad was called just once per app run, I had some debug messages there).
Now I changed navigation logic to the UINavigationController. Everything works fine for the first look - but: the viewDidLoad (for each view) is called everytime I navigate to the view. It is annoying especially in the case of the MapView - the loading of overlays is performed everytime, it takes some time and it causes app crash in some cases.
OK, my questions:
Is it some kind of "common" behavior of NavigationController?
Can I change this behavior so viewDidLoad will be called just once?
And more - How can I influence the "display sequence" of some view?
I understand the logic is probably more complicated but I appreciate any answer or hint ;)
Some related circumstances:
TabBar and Navigation controllers are not combined.
I use storyboards, segues are designed in the UIB, no manual calling like perfomSegue or prepareForSegue in my code. One button triggers segue to MapView.
I use push segues.
I also tried to use modal segues but without any change of that behavior.
any of viewDidUnload is never called during segues among the views.
No memory warning received.
No memory leaks measured both on simulator and iPhone 4.
I tried to build a very simple temporary project / app that is concerned just about the Nav. Controller and other views without ANY coding, just storyboard. It was the same behavior.
There was an issue that causes app crash when I fast and periodically tapped to navigation button and back button between one view and the MapView. In most cases the app crashed when I tapped the back button on the MapView before it was fully displayed (i.e. its overlays). It was fixed when I added a 1 sec. delay method call in the viewDidDisappeared in the MapView. It is not a fair fix, I know ;)
A UITabBarController and UINavigationController are based on fundamentally different paradigms.
The UITabBarController is intended for the UIViewController on each tab to exist independently of each other and for the user to choose which they want to view. viewDidLoad only gets called once for each UIViewController because it is intended that each tab still exists in memory even as the user switches to a different tab.
The UINavigationController is a stack of UIViewControllers where each is related to the one above and beneath itself. The top UIViewController in the stack is always the one that is visible to the user. When a UIViewController is pushed to the stack, its viewDidLoad gets called because it is being loaded into memory. When the top UIViewControllergets poped off the stack, it is unloaded from memory, and viewDidUnload gets called on the way out (viewDidUnload is deprecated in iOS6 and won't get called, but the controller will still get dumped from memory). This is why viewDidLoad gets called every time that the user pushes a particular UIViewController onto the UINavigationController stack.

Performance issue of dismissViewController with Core Data

I have two View Controllers, the main one and popup one. Each of them contains a UITableView and a fetchedResultController to provide data.
the popup is setup inside storyboard, and I add BarButtonItem to dismiss the popup. Dismiss code is very simple
[self.presentingViewController dismissViewControllerAnimated:YES completion:nil]
the issue is It took couple seconds for the popup to dismiss, the app freeze once I click the "dismiss" button.
If I commented the setup of fetchedResultController in the Popup view controller, the dismiss happens immediately. So I assume the problem is with core data. but no idea what it could be.
I have also tried run Instruments to see the problem, no other codes of mine is executed except the above dismiss codes. (although I'm not experienced with Instruments well)
Any help/hint would be appreciated.
OK, It turns out that the performance issue has nothing to do with core data and tableview. the guilty goes to a UISwith, which I apply a Scale to it to make it smaller than usual switch. After I remove the scale code, it behaves normal. so Now the problem is I need to figure out why the scale make it so slow, but it's another question.

Resources