iPhone程序运行流程浅谈

1. 和大多数语言一样,每一个iPhone应用也都是从主函数开始运行,它的main函数都在XCode的Other Reasource逻辑目录下。

   

[cpp] view plaincopyprint?
  1. UIApplicationMain(argc, argv, nil, nil); 
[cpp] view plaincopyprint?
  1. UIApplicationMain(argc, argv, nil, nil);  

    系统会自动给你生成上面的代码,第三个参数和第四个参数指明了应用程序的生命周期管理类和对生命周期管理类产生事件进行响应的委托类,第三个参数被指定为nil则会被视为UIApplication,程序的生命周期管理类一般就是UIApplication,也或者是他的子类(一般没人这么干吧?)。

    第四个参数如果是nil的话,则该函数会去参考**-info.plist这个配置文件来获得一个主NIB文件以完成余下的工作。

    在**-info.plist文件中他会去找Main nib file base name这一列的值作为要载入的NIB文件名。(默认都是MainWindow)

    并且从中指定生命周期管理类的委托。

2. 打开Resource目录下的MainWindowa.xib,会看到Files‘s Owner的Class是UIApplication。

    这个类有一个委托,Interface Builder将他连接到了** App Delegate。这里的意思就是说在运行周期中UIApplication会产生一些事件,但是他交给了** APP Delegate来做处理。

    打开** APP Delegate.h,默认是在Classess逻辑目录下。可以看到UIWindow和一个Controller都被声明成了IBOutlet。

[cpp] view plaincopyprint?
  1. @interface testSDKAppDelegate : NSObject <UIApplicationDelegate> { 
  2.     UIWindow *window; 
  3.     testViewController *viewController; 
  4.  
  5. @property (nonatomic, retain) IBOutlet UIWindow *window; 
  6. @property (nonatomic, retain) IBOutlet testViewController *viewController; 
[cpp] view plaincopyprint?
  1. @interface testSDKAppDelegate : NSObject <UIApplicationDelegate> {  
  2.     UIWindow *window;  
  3.     testViewController *viewController;  
  4. }  
  5.   
  6. @property (nonatomic, retain) IBOutlet UIWindow *window;  
  7. @property (nonatomic, retain) IBOutlet testViewController *viewController;  

    这样就可以在Interface Builder里连接,并且完成相应的初始化工作。

    观察MainWindow.xib的** APP Delegate实例,Interface Builder已经为我们连接上了一个Window和一个Controller实例。

    再看看** APP Delegate.m。

[cpp] view plaincopyprint?
  1. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {     
  2.      
  3.     // Override point for customization after app launch.  
  4.     [self.window addSubview:viewController.view]; 
  5.     [self.window makeKeyAndVisible]; 
  6.  
  7.     return YES; 
[cpp] view plaincopyprint?
  1. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {      
  2.       
  3.     // Override point for customization after app launch.    
  4.     [self.window addSubview:viewController.view];  
  5.     [self.window makeKeyAndVisible];  
  6.   
  7.     return YES;  
  8. }  

    他在UIApplication的这个回调方法中,将Controller的视图加载到了Window上。

    关于这个回调方法文档当中有这么一句话, It is called after your application has been launched and its main nib file has been loaded. 就是说在程序运行起来并且主nib文件完成加载后,这个委托方法将会被调用。

    整个程序目前暂时不需要我们考虑的初始化流程就结束了, 在这之后,我们就可以加入我们程序的逻辑了。

    由于时间仓促,如有疏漏还请大家指出。

    希望本文可以帮到你。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/388372.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Trie树kmpAC自动机后缀数组Manacher

Trie 计数Trie&#xff0c;读清题意很重要 https://vjudge.net/problem/UVALive-5913 kmp AC自动机 模板&#xff1a;https://vjudge.net/problem/UVA-11488 https://vjudge.net/problem/UVA-11019 https://vjudge.net/problem/UVA-11468 https://vjudge.net/problem/UVALive-4…

矩阵线性相关则矩阵行列式_搜索线性时间中的排序矩阵

矩阵线性相关则矩阵行列式声明 (Statement) We have to search for a value x in a sorted matrix M. If x exists, then return its coordinates (i, j), else return (-1, -1).我们必须在排序的矩阵M中搜索值x 。 如果x存在&#xff0c;则返回其坐标(i&#xff0c;j) &#x…

计算机英文版个人简历发文,计算机个人简历英文_英文简历.doc

计算机个人简历英文_英文简历I have the honor to present a brief introduction of myself to you in compliance with the requirements of your graduate admissionI was born in November 7th, 1966, at the town of Changing, Beijing. My parents are doing business and…

一地鸡毛 OR 绝地反击,2019年区块链发展指南

如果盘点2018年IT技术领域谁是“爆款流量”,那一定有个席位是属于区块链的,不仅经历了巨头、小白纷纷入场的光辉岁月,也经历了加密货币暴跌,争先退场的一地鸡毛。而当时间行进到2019年,区块链又将如何发展呢? 近日,全球知名创投研究机构CBInsight发布了《What’s Next …

iphone UITableView及UIWebView的使用

1。新建一个基于Navigation&#xff0d;based Application的工程。 2。修改原来的RootViewController.h,RootViewController.m,RootViewController.xib为MyTableViewController.h,MyTableViewController.m,MyTableViewController.xib。 3。点击MainVindow.xib&#xff0c;将R…

python 的datetime模块使用

1.datetime模块主要是5个类 date #日期类 年月日 datetime.date(year,month,day) time #时间类 时分秒 datetime.time(hour,minute,second,microsecond,tzoninfo),返回18:29:30 datetime #日期时间类 datetime(year, month, day[, hour[, minute[, second[, microsecond[,tzinf…

物联网数据可视化_激发好奇心:数据可视化如何增强博物馆体验

物联网数据可视化When I was living in Paris at the beginning of this year, I went to a minimum of three museums a week. While this luxury was made possible by the combination of an ICOM card and unemployment, it was founded on a passion for museums. Looking…

计算机公开课教学反思,语文公开课教学反思

语文公开课教学反思引导语&#xff1a; 在语文的公开课结束后&#xff0c;教师们在教学 有哪些需要反思的呢?接下来是yjbys小编为大家带来的关于语文公开课教学反思&#xff0c;希望会给大家带来帮助。篇一&#xff1a;语文公开课教学反思今天早上&#xff0c;我上了一节语文…

中国连续十年成马来西亚最大贸易伙伴

中新社吉隆坡1月30日电 (记者 陈悦)马来西亚国际贸易和工业部30日发布的2018年马来西亚贸易报告显示&#xff0c;2018年马来西亚与中国的贸易额约为3138.1亿林吉特(马来西亚货币&#xff0c;约合774亿美元)&#xff0c;较上年同期增长8.1%&#xff0c;约占马来西亚对外贸易总额…

Iphone NSMutableArray,NSMutableDictionary AND 动态添加按钮

一.NSMutableDictionary NSMutableDictionary * tags&#xff1b; 1.NSMutableDictionary 添加内容&#xff1a; [tags setValue:xxx forKey :xxx]; 2.NSMutableDictionary 遍历&#xff1a; for(NSString * title in tags){ //其中得到的title是key } 3.NSMutableD…

bzoj2938: [Poi2000]病毒

被Star_Feel大爷带着做题 明显大力AC机然后找环 本来我一开始想的是先去有另一个病毒为前缀的病毒&#xff0c;结果今天早上写的时候偷懒没写 结果跳fail的时候会跳到中间。。。无语&#xff0c;Star_Feel大爷叫我son或一下now和fail就过了 还有神仙是直接把fail接到儿子的更流…

bigquery数据类型_将BigQuery与TB数据一起使用后的成本和性能课程

bigquery数据类型I’ve used BigQuery every day with small and big datasets querying tables, views, and materialized views. During this time I’ve learned some things, I would have liked to know since the beginning. The goal of this article is to give you so…

中国计算机学科建设,计算机学科建设战略研讨会暨“十四五”规划务虚会召开...

4月15日下午&#xff0c;信息学院计算机系举办了计算机科学与技术学科建设战略研讨会暨“十四五”规划务虚会。本次会议的主旨是借第五轮学科评估的契机&#xff0c;总结计算机学科发展的优劣势&#xff0c;在强调保持优势的同时&#xff0c;更着眼于短板和不足&#xff0c;在未…

iphone开发如何隐藏各种bar

转载至&#xff1a;http://blog.csdn.net/riveram/article/details/7291142 状态条StatusBar [cpp] view plaincopyprint?[UIApplication sharedApplication].statusBarHidden YES; [UIApplication sharedApplication].statusBarHidden YES; 导航条NavigationBar [cpp] v…

Swift5.1 语言指南(九) 闭包

★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号&#xff1a;山青咏芝&#xff08;shanqingyongzhi&#xff09;➤博客园地址&#xff1a;山青咏芝&#xff08;https://www.cnblogs.com/strengthen/&#xff09;➤GitHub地址&a…

服务器被攻击怎么修改,服务器一直被攻击怎么办?

原标题&#xff1a;服务器一直被攻击怎么办&#xff1f;有很多人问说&#xff0c;网站一直被攻击&#xff0c;什么被挂马&#xff0c;什么被黑&#xff0c;每天一早打开网站&#xff0c;总是会出现各种各样的问题&#xff0c;这着实让站长们揪心。从修改服务器管理账号开始&…

脚本 api_从脚本到预测API

脚本 apiThis is the continuation of my previous article:这是我上一篇文章的延续&#xff1a; From Jupyter Notebook To Scripts从Jupyter Notebook到脚本 Last time we discussed how to convert Jupyter Notebook to scripts, together with all sorts of basic engine…

Iphone代码创建视图

要想以编程的方式创建视图&#xff0c;需要使用视图控制器中定义的viewDidLoad方法&#xff0c;只有在运行期间生成UI时才需要实现该方法。 在此只贴出viewDidLoad方法的代码&#xff0c;因为只需要在这个方法里面编写代码&#xff1a; [cpp] view plaincopyprint?- (void)vi…

聊聊flink Table的OrderBy及Limit

序 本文主要研究一下flink Table的OrderBy及Limit 实例 Table in tableEnv.fromDataSet(ds, "a, b, c"); Table result in.orderBy("a.asc");Table in tableEnv.fromDataSet(ds, "a, b, c");// returns the first 5 records from the sorted …

binary masks_Python中的Masks概念

binary masksAll men are sculptors, constantly chipping away the unwanted parts of their lives, trying to create their idea of a masterpiece … Eddie Murphy所有的人都是雕塑家&#xff0c;不断地消除生活中不必要的部分&#xff0c;试图建立自己的杰作理念……埃迪墨…