iOS 一些笔记
来源:互联网 发布:mysql qps 编辑:程序博客网 时间:2024/06/03 21:33
一,获取导航栏相关属性
- 获取包含导航栏的高度:
CGRect rectStatus = [[UIApplication sharedApplication] statusBarFrame]; CGRect rectNav = self.navigationController.navigationBar.frame; CGFloat maxY = rectStatus.size.height+rectNav.size.height;
二,字符串相关
- 截取,判断
NSString *msg = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; //1. 根据某个字符串截取成多个子串 NSArray *subA = [msg componentsSeparatedByString:@"hosten_lym"]; //2. 判断是否包含某个字符串 NSRange range1 = [msg rangeOfString:@"hosten_lym"]; if (range1.location != NSNotFound) { NSLog(@"%@",msg); } //3. 替换指定的字符串 subS = [subS stringByReplacingOccurrencesOfString:@"str" withString:@"reStr"];
三, 关于可变数值或字典的一些事情
1,不可变使用 copy 属性防止数组被其他对象修改,可变必须使用 strong 或者 retain ,原因如下:
@property(nonatomic, copy) NSMutableArray *remoteVideoMutArray; _remoteVideoMutArray = [[NSMutableArray alloc] init];[self.remoteVideoMutArray addObject:dic];
这样做会导致一个崩溃,如图:
实际上使用copy属性后;这里实际上已经转为不可变的数组,再对其赋值,就会导致上述错误,原理如下:
@property(nonatomic, copy) NSMutableArray *remoteVideoMutArray; _remoteVideoMutArray = [[[NSMutableArray alloc] init] copy];[self.remoteVideoMutArray addObject:dic];
因此,可变必须使用 strong 或者 retain ;
关于控制器那些事
- 获取window下rootVC
- (UIViewController *)getCurrentVC{ UIViewController *result = nil; UIWindow * window = ((AppDelegate*)SYS_DELEGATE).window; if (window.windowLevel != UIWindowLevelNormal) { NSArray *windows = [[UIApplication sharedApplication] windows]; for(UIWindow * tmpWin in windows) { if (tmpWin.windowLevel == UIWindowLevelNormal) { window = tmpWin; break; } } } UIView *frontView = [[window subviews] objectAtIndex:0]; id nextResponder = [frontView nextResponder]; if ([nextResponder isKindOfClass:[UIViewController class]]) result = nextResponder; else result = window.rootViewController; return result;}
- 根据rootVC获取最顶层的控制器:
- (UIViewController*)topViewControllerWithRootViewController:(UIViewController*)rootViewController{ if ([rootViewController isKindOfClass:[UITabBarController class]]) { UITabBarController *tabBarController = (UITabBarController *)rootViewController; return [self topViewControllerWithRootViewController:tabBarController.selectedViewController]; } else if ([rootViewController isKindOfClass:[UINavigationController class]]) { UINavigationController* navigationController = (UINavigationController*)rootViewController; return [self topViewControllerWithRootViewController:navigationController.visibleViewController]; } else if (rootViewController.presentedViewController) { UIViewController* presentedViewController = rootViewController.presentedViewController; return [self topViewControllerWithRootViewController:presentedViewController]; } else { return rootViewController; }}
0 0
- IOS 时间一些笔记
- iOS 一些笔记
- 初学ios的一些笔记
- 初学ios的一些笔记
- iOS 一些常用的笔记
- IOS开发中一些重要提示笔记
- IOS笔记:地图的一些东西
- IOS开发的一些技巧以及笔记
- iOS笔记(常用的一些知识点)
- iOS画图的一些笔记CGContextRef
- iOS多线程GCD的一些笔记
- IOS学习笔记——一些零碎知识
- ios开发笔记之常用库的一些整理
- iOS开发笔记--一些实用的宏定义
- IOS学习时的一些笔记(一)
- IOS开发笔记之开发的一些技巧
- IOS学习笔记68 -- 开发的一些奇巧淫技
- iOS学习笔记1-开发的一些奇巧淫技
- SQL语法——保留字的使用
- 开发微信公众号需要配置的几个地方
- CodeForces-450E Jzzhu and Apples 【数学+贪心构造】
- ugui中text的打字机渐显功能
- Gradle配置全局变量
- iOS 一些笔记
- 微信小程序---自动定位,天气预报
- Foxit Reader以及Foxit Phantom如何设置页面固定大小
- 流式布局
- SpringBoot快速入门,不继承SpringBoot父依赖项目
- Java利用System.getProperty("file.encoding")获取编码分析
- SQL语法——视图创建
- SVN
- 我来了,哈哈