读书人

AppDelegat种及协议

发布时间: 2012-08-21 13:00:21 作者: rapoo

AppDelegat类及协议

iOS学习总结—NO.2_AppDelegat类及协议

一、Main函数

main.m 主函数:

AppDelegat种及协议

[AppDelegat class] 返回类型

NSStringFromClass 返回字符串,返回类的名字

二、AppDelegate类

1.AppDelegate.m 程序的入口(方法):

AppDelegat种及协议

系统自动调用此方法。

参数:

1)UIApplication

2)NSDictionary

2.AppDelegate.h (头文件)

1)@interface AppDelegate : UIResponder <UIApplicationDelegate>

<>中是协议(哪个类使用必须实现这个协议的方法)

此协议与此类的父类无关

2)创建协议:

AppDelegat种及协议

AppDelegat种及协议

AppDelegat种及协议

2.1)TestDelegate.h (协议头文件)

【自己写两个方法】

AppDelegat种及协议

实现以上方法:

回到AppDelegate.h头文件

@interface AppDelegate : UIResponder <UIApplicationDelegate>

此类必须遵守此协议 使用此协议的方法。

使用多个协议:

使用协议必须包含此协议的头文件,多个协议之间用逗号隔开。

AppDelegat种及协议

创建一个新类(MyUIControl类)

在MyUIControl.m 中实现 TestDelegate 协议

AppDelegat种及协议

选择AppDelegate.m

AppDelegat种及协议

在AppDelegate 包含刚才新建的类与新建的协议

AppDelegat种及协议

创建一个新类:—elegateUseTest类)

DelegateUseTest.h(头文件)

AppDelegat种及协议

====待续====更新时间未知

本文章介绍的不齐全,大家可以发表评论补充或发送电子邮件给作者。

Mail:superdeveloper@qq.com

读书人网 >PowerDesigner

热点推荐