Purpose of init pattern in obj-c and its use
The initializer pattern is necessary, because the
super
class whose initializer you are calling, can return any kind of object, not necessarily the instance of that class. That's how, for example,NSString
works, it's actually a cluster of classes implementing different kinds of strings optimized for different usage patterns. So callingself = [super init]
forNSString
descendant makes self, for example, anNSCFString
instance.There's a pattern called Designated Initializer in Objective C. If the class has many initializer, one of them is chosen as designated, and all the other should be implemented by calling it, not the super. This is important for correctly overriding initializers in child classes, you should initialize only the designated one, and it will be called under all circumstances (assuming your code is well-written and takes advantage of designated initializers, of course :)
viewDidLoad is called before whole init method is executed
You are not guaranteed to have viewDidLoad
to be called only after the init method is done. viewDidLoad
gets called when a view-controller needs to load its view hierarchy.
Internally, TabBarController
's init method (by calling super.init) is doing something which is causing the view to load.
This applies to all view-controllers. For example: if you create a UIViewController
subclass and do anything with its view
property on init, like adding a subview, or even just setting the backgroundColor
property of the view - you will notice the same behavior.
How to create backBarButtomItem with custom view for a UINavigationController
I'm fairly certain that the backBarButtonItem
is a read-only property. Instead of modifying the backBarButtonItem
, try setting a custom leftBarButtonItem
and hide the backBarButtonItem
:
self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc] initWithTitle:@"Prout" style:UIBarButtonItemStyleDone target:nil action:nil] autorelease];
self.navigationItem.hidesBackButton = YES;
You will also need to make sure you hook up the custom button to call the back action on the UINavigationBar
.
Related Topics
Most Efficient/Realtime Way to Get Pixel Values from iOS Camera Feed in Swift
How to Set Kerning (Spacing Between Characters) on Uinavigationbar Title - Swift or Objective-C
Unusernotificationcenter.Current().Getdeliverednotifications Only Ever Returns an Empty Array
How to Add a Ibaction to a Button Programmatically in Swift 4
Get the Value of Variable Out of Closure Swift
Shift Avplayer Captions When Subview Overlaps Them
Change Push Notification Sound File, Only Works After iOS Reboot
Change Push Notification Sound File, Only Works After iOS Reboot
What Is Correct Way to Notify View Controller from Appdelegate
Daily Local Notifications Are Not Working
How to Center a Label Horizontally for All iOS Devices in Swift
Endless Scrolling (Repeating) Background in Spritekit Game - Swift
@Ibdesignable - View Not Rendering as Expected
App Crash on Device But Works on Simulator iOS
Output Video Size Huge Using Hevc Encoder on iOS
How to Create a Rounded Rectangle Label in Xcode 7 and Swift 2