ios基础笔记(一)
2015-06-01 10:29
393 查看
1.设置按钮文字的尺寸为按钮自己的尺寸 button.size=[button.currentTitlesizeWithFont:button.titleLabel.font]; button.backgroundColor=[UIColorredColor]; 2.常用尺寸 /** 44:cell的默认高度、导航栏的可见高度 49:UITabBar的默认高度 64:从窗口顶部到导航栏底部 20:状态栏高度 320:竖屏情况下的屏幕宽度 480:竖屏情况下的3.5inch的屏幕高度 568:竖屏情况下的4.0inch的屏幕高度 */ 3.textview改变通知 #warning不要设置自己的代理为自己本身 //监听内部文字改变 //self.delegate=self; /** 监听控件的事件: 1.delegate 2.-(void)addTarget:(id)targetaction:(SEL)actionforControlEvents:(UIControlEvents)controlEvents; 3.通知 */ //当用户通过键盘修改了self的文字,self就会自动发出一个UITextViewTextDidChangeNotification通知 //一旦发出上面的通知,就会调用self的textDidChange方法 [[NSNotificationCenterdefaultCenter]addObserver:selfselector:@selector(textDidChange)name:UITextViewTextDidChangeNotificationobject:self]; 4.copy策略,重写setter方法, -(void)setPlacehoder:(NSString*)placehoder { #warning如果是copy策略,setter最好这么写 _placehoder=[placehodercopy]; //设置文字 self.placehoderLabel.text=placehoder; //重新计算子控件的fame, [selfsetNeedsLayout];//重新布局子控件 } 4.UiTabbarbug修复 -(void)tabBarController:(UITabBarController*)tabBarControllerdidSelectViewController:(UINavigationController*)viewController { UIViewController*vc=[viewController.viewControllersfirstObject]; if([vcisKindOfClass:[HMHomeViewControllerclass]]){ if(self.lastSelectedViewContoller==vc){ [self.homerefresh:YES]; }else{ [self.homerefresh:NO]; } } self.lastSelectedViewContoller=vc; } self.lastSelectedViewContoller=vc; /** 其实在这里隐藏着一个问题,如果如图所示你的4个TabBar都是指向4个NavigationController,那么没有问题,运行OK。 但如果你的4个TabBar有任何一个指向的不是NavigationController,那么程序就会crash。因为非NavigationController不能够响应popToRootViewControllerAnimated:方法。 */ if([viewControllerisKindOfClass:[UINavigationControllerclass]]){ [(UINavigationController*)viewControllerpopToRootViewControllerAnimated:YES]; } 5.//自定义Log
#ifdefDEBUG #defineWCLog(...)NSLog(@"%s%d\n%@\n\n",__func__,__LINE__,[NSStringstringWithFormat:__VA_ARGS__]) #else #defineWCLog(...) #endif
6.懒加载
#pragmamark懒加载
//-(NSMutableArray*)imageLinkURL
//{
//if(_imageLinkURL==nil){
//_imageLinkURL=[NSMutableArrayarray];
//}
//return_imageLinkURL;
//}
如果不使用懒加载,数组初始化方式如下,
NSMutableArray*imageArray=[NSMutableArrayarray];
for(AdImageModel*modelinimageModels){
[imageArrayaddObject:model.imageUrl];
}
self.imageLinkURL=imageArray;
不可变数组可以不初始化,可变数组必须初始化
7.block中循环引用
__weaktypeof(clearCache)weakClearCache=clearCache; __weaktypeof(self)weakVc=self; clearCache.operation=^{ [MBProgressHUDshowMessage:@"正在清除缓存...."]; //清除缓存 NSFileManager*mgr=[NSFileManagerdefaultManager]; [mgrremoveItemAtPath:imageCachePatherror:nil]; //设置subtitle weakClearCache.subtitle=nil; //刷新表格 [weakVc.tableViewreloadData]; [MBProgressHUDhideHUD]; }; 8.用搜索子控制器中寻找父控制器
-(UIViewController*)viewController{ for(UIView*next=[selfsuperview];next;next=next.superview){ UIResponder*nextResponder=[nextnextResponder]; if([nextResponderisKindOfClass:[UIViewControllerclass]]){ return(UIViewController*)nextResponder; } } returnnil; }
@interfaceUIView(Extend) -(UIViewController*)viewController; @end @implementationUIView(Extend) -(UIViewController*)viewController{ for(UIView*next=[selfsuperview];next;next=next.superview){ UIResponder*nextResponder=[nextnextResponder]; if([nextResponderisKindOfClass:[UIViewControllerclass]]){ return(UIViewController*)nextResponder; } } returnnil; } @end 使用示例: -(void)buttonPress{ ElectronFrom*electronForm=[[ElectronFromalloc]init]; [[selfviewController].navigationControllerpushViewController:electronFormanimated:YES]; [electronFormrelease]; }
ViewCode
相关文章推荐
- 网易新闻iOS版使用的18个开源组件
- iOS开发 -"ASI"使用实例
- IOS 中的三种弹框模式
- IOS -- 获取WIFI信息API
- IOS应用提交所需的ICON
- Mina学习笔记之IoSessio翻译
- IOS中的__block关键字简单使用
- ios之清除cell缓存,解决cell的重用问题。
- IOS中多版本,多设备类型支持注意事项
- IOS CoreText --- 支持图片及链接的点击
- iOS CoreData详解(五)多线程
- IOS Table中Cell的重用reuse机制分析
- iOS+webservice+soap
- iOS经验汇总帖(持续更新)
- 作为第一期iOS基础班学生,MJ广东开校之我见(原稿)
- ios消息推送--iOS 8.0 后
- JS判断客户端是否是iOS或者Android
- iOS沙盒操作最全讲解
- iOS - AFN - 错误码解决办法(3840)
- nagios