创建线程的方法
NSThread
NSOperationQueue和NSOperation
GCD
主线程中履行代码
[self performSelectorOnMainThread: withObject: waitUntilDone:];
[self performSelector: onThread:[NSThread mainThread] withObject: waitUntilDone:];
dispatch_async(dispatch_get_main_queue(), ^{
});
延时履行
double delayInSeconds = 2.0;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW,
(int64_t)(delayInSeconds * NSEC_PER_SEC));
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
});
[self performSelector: withObject: afterDelay:];
[NSTimer scheduledTimerWithTimeInterval: target: selector: userInfo: repeats:];
loadView
当第1次使用控制器的view时,会调用loadView方法创建view
1般在这里自定义view
第1次使用的控制器view的时候 会调用
viewDidLoad
当控制器的view创建终了时会调用,也就是在loadView后调用
1般在这里添加子控件、初始化数据
viewDidUnload
当控制器的view由于内存正告被烧毁时调用
1般在这里回收跟界面相干的资源(界面都会烧毁了,跟界面相干的资源肯定不要了)