iOS 开发过程中记录的一些小知识(持续更新...)
来源:互联网 发布:java拍卖系统源码 编辑:程序博客网 时间:2024/06/08 06:12
以下内容是在开发中总结的一些小知识,如果有错,请各位看官提出,谢谢!
0、IOS_月薪10k以上知识大总结
1、UIButton的titleLabel是readOnly属性的。
UIButton *btn = [[UIButton alloc] init];
btn.frame = CGRectMake(0, 0, 100, 100);
1) btn.titleLabel.text = @"Halo"; // 错误
这种方式会改变当前的text,但一旦状态改变时(如tap一下)则会恢复默认文字
2)[btn setTitle:@"Halo" forState:UIControlStateNormal];
[btn setTitle:@"Hello" forState:UIControlStateSelected]; // 正确
2、设置控件不可点击可以通过设置 setUserInteractionEnable 属性为NO。
3、读取NSUserDefaults保存的NSArray,返回值全部immutable(不可修改的)。
4、代码新建的.plist文件要 写内容进去 才会在沙盒中 显示。
5、id类型不允许点语法
(id)sender;
sender.tag; // 错误
[sender tag]; //get方法,正确
6、iOS全局变量的声明和调用:
在__AppDelegate中声明:
@property (nonantic, retain) NSString *g_Name;
在任意.m文件中调用:
1) 添加头文件:#import "__AppDelegate.h"
2) 在需要调用的地方:
__AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
appDelegate.g_Name = @"123";
7、iOS开发中经常需要打印CGRect信息:
NSLog(@"%@", NSStringFromCGRect(pickerView.frame));
或者 CFShow(NSStringFromCGRect(pickerView.frame));
打印CGSize信息:
NSLog(@"%@",NSStringFromCGSize(someCG Size ));
附NSLog的格式如下所示:
- %@ 对象
- %d, %i 整数
- %hi 短整型
- %lli 长整型
- %u 无符整形
- %f 浮点/双字
- %0.2f 精度浮点数,且只保留两位小数
- %x, %X 二进制整数
- %o 八进制整数
- %zu size_t
- %p 指针
- %e 浮点/双字 (科学计算)
- %g 浮点/双字 科学技术法(用最简短的方式)
- %s C (char*)字符串
- %.*s Pascal字符串
- %c 字符
- %C unichar
- %lld 64位长整数(long long), 如BOOL值打印
- %llu 无符64位长整数
- %Lf 64位双字
- %lu sizeof(i)内存中所占字节数
8、新建 empty —> aViewController.xib 文件时,要在aViewController.xib 的File's Owner中设置Custom Class为aViewController,然后拖动一个UIView控件进来,在referencing outlet中连接 view 和 File's Owner.
9、在做滑动手势识别时,只要判断手势向右就pop出当前View出错:“nested pop animation can result in corrupted navigation bar
Finishing up a navigation transition in an unexpected state. Navigation Bar subview tree might get corrupted.”
解决方法: 判断手势结束之后再pop
- (void)pan:(UIPanGestureRecognizer*)recognizer
{
CGPoint point = [recognizer translationInView:self.view];
// 向右滑动
if (point.x >0)
{
// 滑动手势结束后pop出栈,否则出现"nested pop animation can result in corrupted navigation bar"
if (recognizer.state ==UIGestureRecognizerStateEnded) {
self.navigationController.interactivePopGestureRecognizer.enabled = YES;
[self.navigationControllerpopViewControllerAnimated:YES];
}
}
}
10、Q:xib文件国际化时如何加载?
A:xib文件localization之后文件名是一样的,只是存在的lproj目录不一样,可以判断系统当前语言环境加载国家化之后的xib。
// Override point for customization after application launch.
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
// 根据当前系统语言环境, 加载国际化文件
NSArray *languages = [NSLocale preferredLanguages];
NSString *currentLanguage = [languages objectAtIndex:0];
NSLog(@"Current iOS Language is %@",currentLanguage);
// 获取Bundle里面的xib文件
NSString *lproj_Path = [[NSBundle mainBundle] pathForResource:currentLanguage ofType:@"lproj" ];
NSBundle *lproj_Bundle = [NSBundle bundleWithPath:lproj_Path];
self.viewController = [[ipjsuaViewController alloc] initWithNibName:@"**ViewController_iPhone" bundle:lproj_Bundle];
} else {
self.viewController = [[ipjsuaViewController alloc] initWithNibName:@"**ViewController_iPad" bundle:nil];
}
11、在xib文件国际化时出现"Could not load the '***.png' image referenced from a nib in the bundle with identifier 'null' ",解决方法是将xib中的图片localization(国际化)。
12、给ImageView增加手势UIGestureRecognizer时,发觉无效果。设置UIImageView.userInteractionEnabled = YES后生效。
13、UIButton如果不做设置的话,点击之后会默认变成蓝色。设置tintColor可去掉这种效果。
- iOS 开发过程中记录的一些小知识(持续更新...)
- (持续更新)日积月累——iOS开发过程中遇到的一些小问题
- iOS开发中一些有用的小代码(持续更新)
- iOS开发中一些小功能代码(持续更新)
- android 开发中遇到的一些小的知识点在此做一个记录(持续更新)
- excel的一些小知识,持续更新
- 一些平时用到的技术小知识(持续更新)
- C#的一些小知识备记(持续更新)
- Android开发小知识(持续更新中)
- Unity知识四:Unity编程过程中遇到的小问题(持续更新)
- iOS开发中总结的小技巧(持续更新中)
- Nhibernate使用过程中记录的一些小知识
- 一些比较好的iOS开发博客持续更新中
- iOS开发小技巧(持续更新中)
- 一些开发中遇到的小问题小记(持续更新中)
- 关于实际开发中优化web的一些小技巧汇总(持续更新中)
- 关于FLEX的一些文章记录(持续更新中)
- Android中一些开发的小技巧总结(持续更新)
- LeetCode 130 Merge k Sorted Lists
- SqlServer2008 数据库同步的两种方式 (发布、订阅)
- Win8/win7 OpenCV-2.4.60+ VS2010永久配置
- Hadoop实验:用java直接使用FileSystem以标准输出格式显示Hadoop文件系统中的文件
- 酵易通微商财富裂变模式,手把手教你做微商
- iOS 开发过程中记录的一些小知识(持续更新...)
- Android中JNI的使用方法
- 沸腾女孩获网友力挺,祝福找到真爱
- 王立平--与或非
- java程序的基本规则和数据类型以及运算符
- 最长公共上升子序列
- Context类中openFileOutput ()函数的使用
- LibSVM 在matlab中的使用方法
- svn合并