[ios 开发笔记]:一句话笔记

1、NSString转int

int a=[@"123" intValue];
同样适用于NSDictionary将NSNumber转为int
 
2、switch(statement) statement只支持int char 枚举

3,要看模拟器的document目录,要将其显隐

On Lion the users/[username]/library is hidden.

Use

chflags nohidden /users/[username]/library

in a terminal to display the folder.

4,iPhone的状态栏可以设置成半透明, 这是众所周知的, 用UINavigationController,在页面切换时, 如果你的子viewController的view是全屏的(480*320) 就会出现错位, 表现是所以的子view会向下偏移了 20像素

 

[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackOpaque];

self.navigationController.navigationBar.translucent = YES;

[self.navigationController.view setNeedsLayout];

self.wantsFullScreenLayout = YES;

5.objectiveC无法检测到对象是否已释放,只能自己管理好。
如:
UIView *uivew=[[UIview alloc]init];
[uiview release];
这时,无法判断uiview是否被释放掉,因为uiview依然指向一个地址,他不为nil。
 
6.xib文件不更新/clear后重加载时只有一片灰色。
修改xib文件,运行,发现没有更新,product->clear依旧。然后将模拟器的app删除,运行,更惨,加载时只有灰色一片。
最后发现虽然在文件夹有看到这个xib,但项目本身并没有引用,在项目Build Phases->Copy Bundle Resources添加xib即可。
 
7.ASIHTTPRequest提前终止异步请求

[[ASIHTTPRequestsharedQueue]cancelAllOperations];

8.UIVIEW层次控制
置顶:[superview bringSubviewToFront:subview];
置底:[superview sendSubviewToBack:subview];
 
9.IOS5.1 对打开系统偏好设置的方式己被禁用。此前IOS5是可用的。
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs:root=TWITTER"]];

10.字符串是否含有某字符串

[str rangOfString:@"abc"].length > 0
 
11.subviews of uiscrollview
今天遍历uiscrollview subviews时发现在0,1位置多了两个水imageview,估计是水平和垂直滚动的指示器。
 
12.移除UIView上所有的subViews 除了遍历移除subView 还可以用这个方法: [[self.view subviews] makeObjectsPerformSelector:@selector(removeFromSuperview)];
 
13.UIBarButtonItem 添加Action
UIButton可以用addTarget,UIBarButtonItem没有这个方法,而是直接用:setAction
14.判断是否retina屏幕

#define isRetina ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 960), [[UIScreen mainScreen] currentMode].s

ize) : NO) 

 

15.withObject:传入整型参数

[self performSelector:@selector(frontButtonScaleUp) withObject:[NSNumber numberWithInt:[sender tag]] afterDelay:delay - elapsed];
[self performSelector:@selector(frontButtonScaleUp) withObject:(id)[sender tag] afterDelay:delay - elapsed];

16.清除UIwebview产的的缓存
有时以页面形式加载,当页面更新时,再次访问也是缓存,怎么清空呢?

[[NSURLCachesharedURLCache] removeAllCachedResponses];

17.屏幕旋转无法触发
[window addSubview:viewController.view]无法触发。
改为
[window setRootViewController:viewController];//仅iOS4.0及以上支持。
原文地址:https://www.cnblogs.com/ejllen/p/3683488.html