I am using Xcode 6 and my project is in ARC mode. In my project, I hook up segues in the storyboard. So far I believe I only used the 'Push' segues. I was wondering, when I do activate this segue, does the previous view controller get deallocated? For example, i am using a 'Push' segue to go from a login screen to the home screen and I want to make sure the log in screen is not hanging around. If it is, how do I deallocate it?
If you want to deallocate it, you can release something in viewDidDisapper.`
- (void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
//TODO: release something
}
`
You don't need to manage in the ARC mode ViewController destroyed, only need to handle something need to manually shut down or release, such as NSTimer.
Related
I have a custom UIView built using several UIButtons. In the viewDidAppear function of a ViewController I take the subviews of this UIView and attach an addTarget to them. Everything works as expected and the embedded UIButtons acts according to the tap events added, selecting and de-selecting the buttons.
But when I instantiate a new ViewController, show it and then it is dismissed, when I'm back to the parent ViewController, the added events are not responding anymore. The rest of the elements of the parent ViewController work (UITableView, other buttons, etc...). This only happens in iOS 12, both simulator and iPhone. In iOS 10 - 11 works like a charm.
What I've seen is that, in IOS 12, when I dismiss the viewController and I'm back to the caller ViewController, no viewDidAppear is being called.
I've lost a couple of day looking for a solution but nothing seems to work. The UIButtons inside my custom UIView class, are responding because I placed some "print()" inside their native tap events, and I get a response when tapping, something must be wrong when I define the addTarget in the ViewController.
Lately I added a UIButton that triggers the function which attachs the event. If I tap on it, the buttons become responsive again. If I call the function as a callback of the Dissmiss method in the Second ViewController... doesn't work. It's like the ViewController wasn't active when I'm back to it.
Must say that the viewControllers are placed inside a Navigation Controller which is inside a Tab Bar Controller.
Any idea?
Disabling "Clear Graphics Context” made the trick... I don't know why, but I suppose it's the XCode Magic that nobody understand.
When I create a new segue using the storyboard (ctrl+drag), it creates creepy lines on my otherwise tidy clean storyboard... I was wondering if there is any method to make them prettier 😅😅
https://ibb.co/iHt9N8
First off. It looks like you are using segues incorrectly. You should not be using segues to go backwards. You should use a segue forward and then dismiss backwards without segue.
Remove any segues that you are using to “go back”.
Next, if it is still too untidy. Separate your app into different areas and use a storyboard for each area.
If you are dealing with a lot of storyboard view controllers, you cannot keep your storyboard clean.
Don't use segues. Just create an instance of the storyboard view controller programmatically and push/present it. Refer to this answer.
I often make use of views in interface builder that live outside of the viewcontroller hierarchy (see screen grab below for simple example).
Before upgrading to Xcode5 I could get this view to appear on the storyboard by writing an IBAction outlet and dragging a connection from the code to the view in the storyboard.
If you paused over the button for a moment it would flash and then open up as a view on the storyboard that is then a lot easier to work with.
Since upgrading this function no longer seems available. Has anyone found out how to get these views to appear on the storyboard?
Edit:
Using the temporary viewcontroller as described in this answer seems one approach, although fiddly since you need to move the UIView stack between viewcontrollers each time you want to edit the layout. Using a separate XIB is starting to seem like the sanest approach.
https://stackoverflow.com/a/13713385/1060154
Finally, we get this back in Xcode 7.
Hallelu!
I'm quite new to iOS Programming. I've done Objective-C for about a year, and now I want to start making apps for the iPhone. I think I'm missing out on something really simple, though. What I've done is this:
First I created a new Single View Application with TestApp as a product name. I enabled Use Storyboards, Use Automatic Reference Counting and Include Unit Tests. After creating the project, I dragged a UIButton onto the View in the storyboard file.
Note that I didn't write a single line of code. I launched my app in the iPhone Simulator and pressed the button, but it's not responding. I know I didn't assign an action to the press of the button, but the gradient of the button isn't changing, as I know it should. The User Interaction Enabled properties of both my view and my button were enabled.
Recently, I've created a few apps in Xcode that worked just fine, but I didn't use storyboards in those projects. Thus, I'm guessing there's something extra to do when using storyboards of which I'm just unaware. I'm using Xcode 4.5 and the iPhone 6.0 Simulator.
I wrote NSLog(#"View was loaded."); statement in the viewDidLoad method of my ViewController to make sure this view controller was actually loaded. (I know my button wouldn't show up if it was the wrong view controller, but I did this just to make sure.)
I also wrote a changeTitle: method in my ViewController to change the title of my button to New Title after it was pressed, just in case the button worked but its gradient just wouldn't respond to a tap. I linked this IBAction to my button, but it wasn't called.
In my ViewController, I created an IBOutlet of a UIButton which I connected to my button. In the viewDidLoad method of my ViewController, I changed the title of my button to New Title, this actually worked. The title of my button changed to this new title when launching my app in the iOS Simulator. The button itself still wasn't responding, though.
As a last try, I also wrote [button setEnabled:YES]; in my ViewController's viewDidLoad method, but this didn't help. My button still doesn't respond to any tap. What am I missing out on?
This is weird. I had an issue with my printer, so I restarted my computer. After this, this issue was suddenly solved as well (just like my printer issue). I'm not sure how this could have affected anything, but I'm glad it works again!
Ran into the same issue.
Apparently Content Reseting the Simulator worked for me
Very strange this..
I am trying to build an fairly simple iPad app that requires me to navigate through multiple views. What I want to do is have some sort of main menu view with multiple buttons on it, and when you click one of the buttons the new view appears and then you work with that. I'm new to iPad development, so I have a few questions about the best way to get this done.
1) If I build the views in Interface Builder, how do I make them aware of each other in Xcode? I can't seem to figure out what I need to do in order to code a button to say "Open View 'Foo'"
2) When I open the views, how should I be adding them in relation to the main menu view? Should I add the new view as a subview of the main menu view, or should I close the main menu view, open the new view, and then reopen the main menu upon closing the first view? I imagine both ways are possible, but are there any performance implications I should be aware of?
Thanks,
Mike
I'm making an assumption that it's more or less the same between iPhone and iPad. I haven't started iPad development yet.
You make view controllers aware of each other by importing their headers in your implementation files
FirstViewController.m
#import "SecondViewController.h"
If you're going for a navigation-style app, you should embed your top level view controller in a navigation controller, then you advance to the next one by calling
SecondViewController *secondVC = [[SecondViewController alloc] initWithNibName:#"SecondViewController" bundle:nil];
//set any properties
[self.navigationController pushViewController:secondVC animated:YES];
[secondVC release];