Basic knowledge of IOS development-fragment 28, basic knowledge of ios-28
1: General weakify and strongify
/*** Strong/weak reference conversion, used to solve the circular reference problem between the block and the strong reference self. * Call method: '@ weakify_self' implements weak reference conversion, '@ strongify_self' implements forced reference conversion ** example: * @ weakify_self * [obj block: ^ {* @ strongify_self * self. property = something; *}]; */# ifndef weakify_self # if _ has_feature (objc_arc) # define weakify_self autoreleasepool {}__ weak _ typeof _ (self) weakSelf = self; # else # define weakify_self autoreleasepool {}_ block _ typeof _ (self) blockSelf = self; # endif # ifndef strongify_self # if _ has_feature (objc_arc) # define strongify_self try {}@ finally {}_ _ typeof _ (weakSelf) self = weakSelf; # else # define strongify_self try {}@ finally {}_ _ typeof _ (blockSelf) self = blockSelf; # endif/***, used to solve the circular reference problem between a block and a strongly referenced object * Call method: '@ weakify (object)' to implement weak reference conversion, '@ strongify (object) 'example of implementing strong reference conversion **: * @ weakify (object) * [obj block: ^ {* @ strongify (object) * strong_object = something; *}]; */# ifndef weakify # if _ has_feature (objc_arc) # define weakify (object) autoreleasepool {}__ weak _ typeof _ (object) weak ##### object = object; # else # define weakify (object) autoreleasepool {}_ _ block _ typeof _ (object) block ##### object = object; # endif # ifndef strongify # if _ has_feature (objc_arc) # define strongify (object) try {}@ finally {}_ _ typeof _ (object) strong ##### object = weak ##### object; # else # define strongify (object) try {}@ finally {}_ _ typeof _ (object) strong ##### object = block ##### object; # endif
Use (the two macros are regarded as a pair, and weak is used before strong ):
@ Weakify (self); // defines the self_weak _ variable of _ weak [RACObserve (self, name) subscribeNext: ^ (NSString * name) {@ strongify (self ); // The local area defines a _ strong self pointer pointing to self_weak self. outputLabel. text = name;}];
2: The objc runtime dynamically adds attributes.
Note: A New attribute is added to the class extension. Generally, class extensions only allow adding methods. Objc/runtime. h must be introduced first, mainly in the following two methods:
Value assignment: OBJC_EXPORT void assign (id object, const void * key, id value, objc_AssociationPolicy policy) value: OBJC_EXPORT id objc_getAssociatedObject (id object, const void * key)
Instance (reference ):
UILabel+Associate.h#import <UIKit/UIKit.h>@interface UILabel (Associate)- (void) setFlashColor:(UIColor *) flashColor;- (UIColor *) getFlashColor;@endUILabel+Associate.m#import "UILabel+Associate.h"#import <objc/runtime.h>@implementation UILabel (Associate)static char flashColorKey;- (void) setFlashColor:(UIColor *) flashColor{ objc_setAssociatedObject(self, &flashColorKey, flashColor, OBJC_ASSOCIATION_RETAIN_NONATOMIC);}- (UIColor *) getFlashColor{ return objc_getAssociatedObject(self, &flashColorKey);}@end
Call code:
UILabel *lab = [[UILabel alloc] init]; [lab setFlashColor:[UIColor redColor]]; NSLog(@"%@", [lab getFlashColor]);
3: navigationController popToViewController jumps to the upper layer
NSUInteger index=self.navigationController.viewControllers.count-3; [self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:index] animated:YES];
If the animation is to flip the page, it may be because the current page has a keyboard. You can recycle the keyboard first, and then the action will turn back to the normal animation effect.