定义宏进行懒加载!!!!!!!!!!!!
#define ArrayLazyLoad(x) if (!x) { x = [NSMutableArray new];}return x
常量 和局部变量 block 中需要用__block修饰才可以在block内部修改它的值,全局变量和全局常量变量不用修饰
循环引用是自定义的block才会造成,系统的不会 归根结底还是堆栈中的释放问题.
懒加载!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1!!!!!!!!!!!
/**<#懒加载#>*/
- (<#类名#>)<#变量名#> {
if (_<#变量名#> == nil) {
_<#变量名#> = [[<#类名#> alloc]init];
}
return _<#变量名#>;
}
匿名类!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@interface <#类名#> ()
/** <#名字#> */
@property (nonatomic ,<#assign#>)<# NSString#> * <#name#>;
@end
表格视图快捷块!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
/**创建表格试图*/
UITableView * table = [[UITableView alloc]initWithFrame:self.view.bounds style:UITableViewStylePlain];
table.dataSource = self;
table.delegate = self;
[self.view addSubview:table];
self.tableView = table;
属性快捷块!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
/** <#名字#> */
@property (nonatomic ,<#assign#>) <#NSString#> * <#name#>;
警告框快捷块!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
/**<#警告弹出#>*/
UIAlertController * alert = [UIAlertController alertControllerWithTitle:<#@"弹出警告"#> message:<#@"警告信息"#> preferredStyle:UIAlertControllerStyl<#eAlert#>];
UIAlertAction * action = [UIAlertAction actionWithTitle:<#@"go"#> style:UIAlertActionStyl<#eDefault#> handler:^(UIAlertAction *action) {
}];
[alert addAction:action];
[self presentViewController:alert animated:YES completion:nil];
监听中心快捷块!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
/**<#创建监听中心#>*/
//写在方法中
[[NSNotificationCenter defaultCenter]addObserver:<#self#> selector:@selector(<#keyboardNotice:#>) name:<#UIKeyboardWillShowNotification#> object:nil];
[[NSNotificationCenter defaultCenter]addObserver:<#self#> selector:@selector(<#keyboardNotice:#>) name:<#UIKeyboardWillHideNotification#> object:nil];
- (void)keyboardNotice:(NSNotification*)notice {
if ([notice.name isEqualToString:<#UIKeyboardWillShowNotification#>]) {
self.view.bounds = CGRectMake(0, 100, self.view.bounds.size.width, self.view.bounds.size.height);
}else if ([notice.name isEqualToString:<#UIKeyboardWillHideNotification#>]){
self.view.bounds = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height);
}
}
原文:http://www.cnblogs.com/zhang6332/p/6273351.html