您的位置:首页 > 移动开发 > IOS开发

iOS开发各种小知识

2015-07-02 14:17 441 查看
1.父视图的透明度属性会传递给子视图
2.iPad可以运行iPhone的程序 iPhone不可以运行iPad的程序
3. //判断是iPad 还是iPhone

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {

NSLog(@"iPad");

} else {

NSLog(@"iPhone");

}

4. //判断系统的版本号

if ([[UIDevice currentDevice].systemVersion floatValue] > 7.0) {

NSLog(@"%@", [UIDevice currentDevice].systemName);
}
5 self 在+方法中指类名 在-方法中指类的对象

1.isEqual不知道为什么不可以判断一个对象是否为某个类

例如

if([[[array1 objectAtIndex:0] class] isEqualTo:[NSString class]])

{

NSLog(@"是nsstring类型");

}

这个方法是错误的❌;

2.在模拟登录注册时候发现的疑难杂症

为什么在程序中使用了gets()函数获取字符产 ,就不可以用nslog函数打印了呢。❓❓❓❓❓❓❓❓❓❓❓❓❓❓❓❓❓❓❓❓

那是因为定义字符串的时候不要用指针 要用数组

例如 char *str; ❌

char str[100] ✅

3.⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠

注意 要给可变数组增加元素 那么必须要给可变元素初始化 不然增加不了

例如 NSMutableArray *array = [NSMutableArray arrayWithCapacity:0];✅

NSMutableArray *array = nil ❌

4.数据库使用参数sql语句的时候

不能调用exec函数 要用step函数 切记3⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠⚠

5.修改barbuttonitem的外观 这个方法设置一次全部都会变 全局设置

UIBarButtonItem *appearanceBarButton = [UIBarButtonItem appearance];

NSMutableDictionary *dict = [NSMutableDictionary dictionary];

dict[NSForegroundColorAttributeName] = [UIColor redColor];

[appearanceBarButton setTitleTextAttributes:dict forState:UIControlStateNormal];

6//第一次使用类的时候调用

+ (void)initialize

{

if (self == [self class]) {

}

}

7//设置键盘的辅助视图

UITextField *textField = [[UITextField alloc] init];

textField.inputAccessoryView = [[UIView alloc] init];

8//图片拉伸

UIImage *newImage = [image resizableImageWithCapInsets:UIEdgeInsetsMake(15, 22, 15, 22)];

9 btn.adjustsImageWhenHighlighted = NO;//表示button高亮状态下 图片不会变颜色

10.NSClassFromString(<#NSString *aClassName#>)//根据字符串转换为类名

11.tableViewController 貌似可以实现自动刷新的功能 不是很确定 还有待确认

12 开两个模拟器的命令

cd /Applications/Xcode.app/Contents/Developer/Applications/

open -n iOS\ Simulator.app/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: