粗糙的iOS笔记之一应用生命周期

1. UICollectionViewController
       1.1概念
                     从iOS6开始, 是一个变异的TableViewController,可以将其认为是一个二维的表视图。
       1.2布局特点:
              FlowLayout 流式布局
       1.3和TableViewController 比较:
                     TableViewController         CollectionViewController
                            section                                             section
                            row                                             item
                            cell                                          cell            
              cell:UITableViewCell或子类      cell: UICollectionViewCell
              协议:
                     TableViewDatasource            CollectionViewDatasource
                三问                                                三问
                     TableViewDelegate                CollectionViewDelegate
                            响应                                                 响应
2. UITabBarController(标签控制器)
       2.1  概念
              控制器的控制器
       2.2创建
                            1) 经常需要先创建出要包含的多个VC
                            2)用TabBarController包含这些VC
       [Demo2]
       2.3TabBar中的按钮Title和image需要配置:
                     在具体的VC中设置属性:
                     .tabBarItem.image
                     .tabBarItem.title
                     或.title
       2.4tabBar和Navigation一起使用
                     1)之间的关系:
                            self.window.rootViewController= UITabBarController;
                            UITableBarController.viewControllers= @[UINavigationController, UINavigationController, UIViewController];
                            UINavigationControllerpush: UIViewController
                     2)推新的界面:
                            push时默认新界面会保留TabBar,如果不希望看见,在Push之前可以设置隐藏:
                                    .hidesBottomBarWhenPushed
                            present推新界面时,新界面肯定不会出现TabBar的。
3. 视图和视图控制器的生命周期
       3.1ViewController对象本身的创建和销毁
                     1)创建
                                    .init  (不多)
                                    .initWithXxxx(Style…)  (不多)
                                    .initWithNibName:xxx bundle:xxx  (使用xib文件初始化时)
                                    .initWithCoder:xxx(使用Storyboard时初始化方法)
                     2)属性
                            私有属性 @property(nonatomic,strong)NSMutableArray *data;
                                    一般会在init方法中创建此属性对应的对象。
                                    在getter方法中创建,这样就只有需要使用此属性时才创建此对象。(Lazyloading)
                            公开的属性一般是由外面赋值进来的,或是只读属性。
                     3)释放
                            dealloc方法   在ARC下,此方法一般不太关注
       3.2ViewController对象的生命周期
                     1) viewDidLoad
                            显示之前,加载nib文件后调用
                            经常用于将数据赋值到显示界面的控件上。
                     2)viewWillAppear
                            视图在显示之前调用
                            经常将更新界面的代码写在此
                     3)viewDidAppear
                            视图显示之后调用
                            当界面播放动画时用
                     4)viewWillDisappear  /  viewDidDisappear
                            视图即将消失时/消失后调用
                            如果在viewWillAppear/viewDidAppear中分配的某些资源,就在此释放这些资源
        3.3 应用程序的生命周期
              非运行状态
              前台非活动状态
              活动状态
              后台状态
              挂起状态        


子线程不能更改主线程界面的东西  或者说  子线程不能更改界面

didFinishLaunchingWithOptions 方法

1.初始化模型

2.配置第三方框架信息

3.如果不使用Storyboard就要初始化rootViewController

4.应用程序间通信

5. 处理通知

applicationWillResignActive

1.暂停游戏

2. 暂停各种Timer

applicationDidEnterBackground

1.释放各种资源

2.各种收场 (申请后台操作)

当前要下载多个文件,赶快下载最后一个文件,其它就不下载了(进入后台后 只有10分钟时间存活)

3.提示服务器(申请后台操作)

提示服务器当前用户不在线

applicationDidBecomeActive

恢复各种TImer以及游戏

后台操作的申请

// <span style="color: rgb(51, 153, 153); font-size: 14px;">1).向操作系统请求后台运行,并获取后台运行任务码</span>
<span>	</span>// 在.h文件中声明属性 <pre code_snippet_id="234367" snippet_file_name="blog_20140313_2_175873" name="code" class="objc">	// @property (nonatomic) UIBackgroundTaskIdentifier bgTaskIdentifier;
 
 

 
</pre><pre code_snippet_id="234367" snippet_file_name="blog_20140313_3_5748007" name="code" class="objc">	// 在<span style="color: rgb(51, 153, 153); font-size: 14px;">applicationDidEnterBackground方法中</span>	<pre code_snippet_id="234367" snippet_file_name="blog_20140313_3_5748007" name="code" class="objc">	self.bgTaskIdentifier =  [application beginBackgroundTaskWithExpirationHandler:^{
        // 在后台运行任务到期时运行这个代码块
	//  4).处理在时间结束后,后台任务仍然没有做完的情况<pre code_snippet_id="234367" snippet_file_name="blog_20140313_3_5748007" name="code" class="objc">		[application endBackgroundTask:self.bgTaskIdentifier];
    		self.bgTaskIdentifier = UIBackgroundTaskInvalid;
}];
 
 
// 2).使用另外一个线程,执行后台运行代码 
	dispatch_queue_t queue =
    	dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
    	dispatch_async(queue, ^{
        	// 耗时操作 后台运行代码<pre code_snippet_id="234367" snippet_file_name="blog_20140313_4_4384804" name="code" class="objc">		for (int i = 0; i < 10000; i++) {
            		NSLog(@"%d",i);
            		[NSThread sleepForTimeInterval:1];
<p class="p1"><span class="s1">			// </span>在后台运行剩余时间</p><p class="p1"><span class="s2"><span style="white-space: pre;">	</span>NSLog</span><span style="font-family: Arial, Helvetica, sans-serif;">(</span><span class="s3" style="font-family: Arial, Helvetica, sans-serif;">@"%.2f"</span><span style="font-family: Arial, Helvetica, sans-serif;">,[application </span><span class="s2" style="font-family: Arial, Helvetica, sans-serif;">backgroundTimeRemaining</span><span style="font-family: Arial, Helvetica, sans-serif;">]);</span></p>        	}
<pre code_snippet_id="234367" snippet_file_name="blog_20140313_6_1068972" name="code" class="objc" style="color: rgb(51, 153, 153); font-size: 14px;">		3).告知操作系统后台任务执行结束
[application endBackgroundTask:self.bgTaskIdentifier];self.bgTaskIdentifier = UIBackgroundTaskInvalid;
 
 

 
}); 
 
 
 
 
 
 
 
 
 
<p><span style="font-size: 18px;">给大家推荐一个swift视频教程,后续会不断更新,下载文件需要验证多次,有点耐心哦!</span></p><p><span style="font-size: 18px;"><a target=_blank target="_blank" href="http://www.400gb.com/file/68575211">从OC转移到swift:环境与变量</a>
</span></p><p><span style="font-size: 18px;"><a target=_blank target="_blank" href="http://www.400gb.com/file/68478822">swift进阶可能值</a>
</span></p><p><span style="font-size: 18px;"><a target=_blank target="_blank" href="http://www.400gb.com/file/68478567">swift枚举扩展泛型</a>
</span></p><p><span style="font-size: 18px;"><a target=_blank target="_blank" href="http://www.400gb.com/file/68477438">类初始化属性方法</a>
</span></p><p><span style="font-size: 18px;"><a target=_blank target="_blank" href="http://www.400gb.com/file/68477021">元组闭包</a>
</span></p><p><a target=_blank target="_blank" href="http://www.400gb.com/file/68476769"><span style="font-size: 18px;">变量字符串集合循环</span></a></p>
 
 
 

                
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值