I am trying to switch the UIViewController category to viewWillAppear:. But getting this warning.
viewWillAppear:
A category implements a method that is also implemented in a class
@implementation UIViewController (ViewWillAppearCategory) -(void)viewWillAppear:(BOOL)animated { //......... } @end
I want some things to appear on all screens while watching, so I donβt want to touch the whole screen . therefore, go with the category.
I can implement some method in a subclass, and I can call this method in all VCs (full screen). But I do not want this. It is automatically called up on the screen, a call will appear. Is it any idea to do this or make any mistake above?
. . . , . .
Method Swizzling, , .
, , .
http://nshipster.com/method-swizzling/
, . , UIViewController, , MyUIViewController, :
-(void) viewWillAppear:(BOOL) animated { // do your "category" stuff }
UIViewControllers MyUIViewController :
-(void) viewWillAppear:(BOOL) animated { [super viewWillAppear:animated]; // rest of code for this class }
, - :
super
[super viewWillAppear:]
, UIViewController, viewWillAppear:, :
UIViewController
, . , , UINavigationControllerDelegate , .
UINavigationControllerDelegate
viewWillAppear documentation:
viewWillAppear
, , . . , . , super - .
, .
, , . , , UIViewController, viewWillAppear .
//UIViewController+CustomCategory.h @interface UIViewConctroller (CustomCategory) - (void)performCustomization; @end //UIViewController+CustomCategory.m @implementation UIViewController (CustomCategory) - (void)performCustomization { // Do custom stuff⦠} @end
//MYViewController.m #import "UIViewController+CustomCategory.h" - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; [self performCustomization]; }
, . , , , , .
, ,
#pragma clang diagnostic push #pragma clang diagnostic ignored "-Wobjc-protocol-method-implementation" -(void)viewWillAppear:(BOOL)animated { NSLog(@"I get callback here too"); } #pragma clang diagnostic pop
, , XCode.
Source: https://habr.com/ru/post/1534988/More articles:How to group elements of a numpy array with the same value in separate numpy arrays - pythonconvert excel file to pdf using java, itext and POI API and save settings - javaHow to display value labels above chart diagrams using chart.js - javascriptManaging the number of threads by available memory in Java - javaIs it possible to hide a branch in the git repository for all remote clones? - gitFinding source IP address when binding to 0.0.0.0 - pythonstream.copyto with progress message - c #MathNet.Numerics vs. Matlab Forward Fourier Responding To Mismatch? - matlabDecimal numeric symbolic link not allowed: forbidden or text? - htmlAngularJS with Grunt - connecting to another server - angularjsAll Articles