I'm new to iOS development and I have hit a snag, my app works fine, however there are memory issues. I have created multiple view controllers, with buttons. In Interface Builder I have created a modal segue between the button and the next view.
This all works great, however through using instruments, I can see that as you move along the app the memory is increasing, getting as high as 200mb, which seems to then cause a crash. I'm guessing it's because the app is loading the view controllers and their contents are staying in the memory of the device and are pileling up.
I have tried converting the project to ARC, this doesn't seem to have any effect, is there something obvious that I have missed?
Any help would be great :)
Thanks
Gary
Related
I have created two UIViewControllers in IB.
PROBLEM 1: I can't make the 2. VC transparent.
I have read a lot of stackOverFlow solutions but nothing seems to work in my case.
I have tried the following setup in IB both in my current project and in this simple project and something strange occurs (IB,for 2.VC):
Setting the alpha value below 0,5
Setting opaque to "checked"
Setting the background color to "black"
https://imageshack.com/i/kqdXWk9Jp
The second VC gets pushed when I click "GO TO NEXT VC" (push or modally , doesn't matter) and while he is being pushed I see the the result I want:
https://imageshack.com/i/idXUCFCPp
... and when the push is finished the new VC changes from being transparent to black (not transparent):
https://imageshack.com/i/iqmLw8D1p
I have no clue why this is happening and I cant get it to stop working like that.
Q1: Why is this happening?
Q2: Why can't I change the properties of the views programmatically when the views are created with IB?
I have done this thousand times WITHOUT using IB. As soon as I start using IB things don't work like they are supposed especially when I try to edit stuff programmatically.
When I do all of these steps without IB only in code everything works perfectly fine but I need to use the IB in my next project. I am using Xcode 5.1.1. on mac mini (late 2009) with Mavericks.
Sorry for bad English.
Your problem is because the memory management of iOS removes the previous interface ViewController, to save resources.
After iOS7, you can customize the transition viewControllers. Please read: UIViewControllerAnimatedTransitioning Protocol Reference.
I also had the same problem and managed to solve it by following the tutorial Custom UIViewController Transitions.
If you are still having doubts, there is another tutorial to help you: iOS7: Custom Transitions.
Hope you get success!
I found that a previously normally working iPad storyboard started working weirdly upon introducing auto-layout. In particular it seems not to properly show different ViewControllers when clicking different annotations but instead it always shows the first one whatever more annotations are clicked. When I disable auto-layout everything works fine again. Apple responded to my request hinting to a problem in the handling of segues:
#Apple: 'When running a segue from A -> B, it is not our intention that that segue over and over again will result in a chain like A -> B -> C -> D because the original transition is A -> B. However it would make sense if you had a self-referencing segue and you called performSegueWithIdentifier over and over again because you in that case are having the same instance just added to itself. I think you were just getting lucky before and that turning auto layout on was just enough to point that out.'
Yet all the hits I found on the web like in:
How to call a segue from a disclosure button on a map pin?
and
MKMapView show DetailView - How to make a segue
are quite the same as the the code I used and Apple says it is wrong; notwithstanding the iPhone version keeps on working and the problem just arises on the iPad.
Any hint before they crank up another funny suggestion?
Unfortunately the problem, the way it went the way it returned. Eschewing the possibility I ran mad, the same code including the one on the iTunes Store now, started presenting the problem again. I also tested it on another iPad and it presents the same problem leaving me totally in the dark. All the thing seems crazy.
After a number of tests I found that a normal working iPad storyboard starts working weirdly upon introducing auto-layout. In particular it seems not to properly pop-up dismissed views by always recycling the same view controller and to also badly handle the queue of instantiated view controllers. When I disable auto-layout everything works fine again. Does anyone know if this bug is known to Apple or there is a fix?
Not been able to complement the question with new information, I posted a new one at:
Triggering segues from annotations
I have a very very old iPhone/iPad app, actually it was my very first Objective-C app, I started learning iOS programming on it. Now I want to update it a bit but have following problem:
The app has never had any viewController. When I started writing it, I wasn't familiar with MCV and Interface Builder. First version was just for iPhone and it made the UI manually by just positioning UILabels and UIButtons in UIApplicationDelegate's didFinishLaunchingWithOptions via addSubview directly into self.window (there is MainWindow.xib but it's empty). A couple of months later I created iPad version. It has all the UI created in Interface Builder in a single MainWindow_iPad.xib. There are no other xibs, just UILables and UIButtons placed directly in MainWindow_iPad.xib and no view controller was used again.
Now, a couple of years later, I want to update this veteran app a bit. I want to add a root view controller so I set window.rootViewController in UIApplicationDelegate's didFinishLaunchingWithOptions. I have no problem with the iPhone version, it works a treat. But I have troubles with the iPad one. After setting window.rootViewController, the app doesn't interact to any touch at all. It loads, the UI is created but it's just frozen.
Any idea what could be wrong? Thanks a lot!
Don't tell me I should throw it away and write it again from scratch in a normal "experienced way", I know this would be the best way but I don't need to update it that much to waste so much time.
I am a learning developer that is always trying to learn new things. I am playing around with more advanced views and subviews, and am currently trying to use a view within a view. I know how to use modal views, but in this case I want both views to be present and running. So, picture the iPad running an unscaled iPhone app, that is basically the same idea of what I am trying to do. I can get the view to load up just fine, however, when I use buttons or anything inside the views that the user interacts with, the application crashes. It gives the following error message: EXC_BAD_ACCESS (Code=2, Address=0x17). What's weird is that there is no output from the debugger on this issue. I have tried to use a delegate (the way you do in a modal view) and it doesn't change anything. Any help is much appreciated :)
You can, of course, put many views inside a view.
EXC_BAD_ACCESS means you, or some object, is trying to access an object which has been deallocated.
I can mostly promise you that the issue is not because you are putting a view in a view, that statement and actually doing that is fine.
How you go about doing it, and how you handle everything is a different story.
You didn't provide any code or context as to where and how you are adding a view to a view, which is probably where the issue is arising. Enabling NSZombie as suggested by xlc0212 is a great idea to help diagnose the problem.
Hope this helps