should I write [super viewDidLoad]? [duplicate] - viewdidload

This question already has answers here:
Do I always have to call [super viewDidLoad] in the -viewDidLoad method?
(8 answers)
Closed 8 years ago.
I'm writing a navigation based app. (it has modal segues too)
I'm not sure if I should keep [super viewDidLoad]; call or not. should I write code after this line of code or before it? how about [super viewDidUnload]; and similars?

You don't have to; according to the documentation, it's a stub function, so it doesn't do anything useful in non-subclasses.
Moral: always read the docs.

Related

What does UIViewController class do in viewDidLoad? [duplicate]

This question already has answers here:
`[super viewDidLoad]` convention
(2 answers)
Closed 9 years ago.
As in the title, I was wondering what is the "default" implementation of viewDidLoad in UIViewController? Does it really do anything? Also does it matter if in my UIViewController's subclass I write
-(void)viewDidLoad{
[super viewDidLoad];
/*custom code here*/
}
or
-(void)viewDidLoad{
/*custom code here*/
[super viewDidLoad];
}
?
P.S. This is not a duplicate, in other questions people ask when should they call [super viewDidLoad], while my main concern is what the UIViewController's implementation do with it.
That implementation does nothing, and can safely be removed if you have no setup to do after the view loads. However, it is fairly rare to have no custom setup to do here; this is the place where your view controller is telling you that all of its UI objects are available to customize with data. It's included in the template with an empty implementation as a reminder: here's where to do this.
As far as when to call super: the general expectation is that setup or initialization methods call super before doing work, and teardown methods call super after doing work.
ViewDidLoad Method Called after the controller’s view is loaded into memory.
This is where you want to instantiate any instance variables and build any views that live for the entire lifecycle of this view controller. However, the view is usually not yet visible at this point
This method is called regardless of whether the view hierarchy was loaded from a nib file or created programmatically in the loadView method. You usually override this method to perform additional initialization on views that were loaded from nib files.
For detail Information

Is NSNotificationCenter removeObserver in ARC needed? [duplicate]

This question already has answers here:
KVO and ARC how to removeObserver
(3 answers)
In ARC do we need to send removeObserver: explicitly?
(4 answers)
Closed 9 years ago.
Does adding an observer increase the retain count of an object?
If yes, does ARC handle the removing of this observer too? If not, where should I remove the observer?
You should explicitly remove the observer even you use ARC. Create a dealloc method and remove there..
-(void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
If you see the method you don't need to call [super dealloc]; here, only the method without super dealloc needed.
UPDATE for Swift
You can remove observer in deinit method if you are writing code in swift.
deinit {
NSNotificationCenter.defaultCenter().removeObserver(self)
}

ViewController subclasses should have [super viewDidUnload] in each?

I have subclassed UIViewController 3 times. Should each one have [super viewDidUnload] in it?
Hopefully a simple question, and not too daft! Thanks.
- (void)viewDidUnload
{
...
[super viewDidUnload]; //<<< In all 3 subclasses?
}
Yes, you should call super in each class.
Note that this method is deprecated in iOS 6.0. Views are no longer purged under low-memory conditions and so this method is never called.
You should call [super viewDidUnload] in viewDidUnload method call.
You should read the ios dev document (memory management subsection). I am sure it will help you to understand the answer of your question ;)

problem with method init of view controller class

I try to run programm (http://www.edumobile.org/iphone/iphone-programming-tutorials/calculator-application-in-iphone/) from here, but i have problem with init method. While running programm don't creates variables (current, previous). Where is it call init-method in xCode?
the init method is never called because the ViewController is loaded from a nib file.
You could move those 3 lines into viewDidLoad. But to be honest, I think it's better when you trash the project and look for something better. Because this is not the only problem of the project.
If you learn with these "tutorials" you will have huge problems later.
That guy has obviously never heard about memory management.
But if you want to try, add this method to the #implementation of calciViewController
- (void)viewDidLoad {
[super viewDidLoad];
operator=0;
current =[[NSString stringWithString:#"0"]retain];
previous =[[NSString stringWithString:#"0"]retain];
}

iPhone viewDidLoad

When I override the method viewDidLoad, should I call it first and then write my code or is it the other way around?
Call super's implementation. The approach is FIFO:
- (void)viewDidLoad
{
[super viewDidLoad];
// code...
}
- (void)viewDidUnload
{
// code...
[super viewDidUnload];
}
To gain a little more insight, look at Apple's documentation on View Controller: http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/BasicViewControllers/BasicViewControllers.html
Also see this similar (dup?) question and answer: `[super viewDidLoad]` convention
No, you don't need to call [super viewDidLoad].
Let's be real here: Apple is not going to break thousands of apps, including those based on their published sample code, by deciding an event they're not currently handling suddenly needs to do something that developers may or may not want to stop and it's critical that if you don't need different behavior you not stop the event.
If Apple needs to do something like this, they'd add a specific new event. For example, and this is a ridiculous example, viewConvertTo3D.
Call the super if it matches your pattern. In fact, you probably should make the effort to learn Apple's standard nesting pattern. Don't call it if it doesn't, or if you care more about keeping your sources small. Extra code is not future proofing.
from: here