iOS 网络与多线程--7.Performselector消息处理方法
2015-12-04 23:19
429 查看
创建一个IOSApp类
IOSApp.h文件
IOSApp.m文件
ViewController.m 文件
IOSApp.h文件
#import <Foundation/Foundation.h> @interface IOSApp : NSObject // 1.添加一个无参数的方法 -(void)printInfomation; // 2.添加一个有参数的方法 -(void)buyApp:(id)appName; @end
IOSApp.m文件
#import "IOSApp.h" @implementation IOSApp // 3.实现头文件中无参数的方法 -(void)printInfomation { NSLog(@"Xcode Interactive Tutorials"); } // 4.实现头文件中带有参数的方法 -(void)buyApp:(id)appName { NSLog(@"Buy the App%@",appName); } @end
ViewController.m 文件
#import "ViewController.h" // 5.导入钢材创建的类的头文件 #import "IOSApp.h" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. // 6.初始化一个类对象 IOSApp *app = [[IOSApp alloc] init]; // 7.@selector()可以理解为取类方法的编号,它的行为基本可以等同c语言中的函数指针,它的结果是SEL类型。 SEL method = @selector(printInfomation); // 8.respondsToSelector()方法,用来判断是否有,以某个名字命名的方法。 if ([app respondsToSelector:method]){ // 9.performSelector是由运行时系统负责去找方法的,在编译时不做任何校验 // 调用方法 [app performSelector:method]; } SEL method2 = @selector(buyApp:); if ([app respondsToSelector:method2]) { // 调用方法 [app performSelector:method2 withObject:(@"Photoshop Interactive Tutorials")]; } } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end
相关文章推荐
- 1.1安装CentOS6.5和网络配置
- JAVA中Socket编程(一)---通过TCP协议实现通信
- HDU 1532 Drainage Ditches 网络流模板题(Dinic)
- 41.网络编程(Get 同步 异步block)
- centos6.5安装mysql-udf-http日记
- 网络流问题
- Ubuntu中启用关闭Network-manager网络设置问题!
- JAVA HTTP POST参数为一个对象或数组
- JAVA HTTP POST参数为一个对象或数组
- iOS 网络与多线程--6.下载并保存网络图片
- nodejs发起HTTPS请求并获取数据
- poj--1637--Sightseeing tour(网络流,最大流判断混合图是否存在欧拉图)
- poj--1637--Sightseeing tour(网络流,最大流判断混合图是否存在欧拉图)
- UNIX网络编程笔记(6):I/O复用之select函数
- centos下httpd-2.4的编译安装
- centos下httpd-2.4的编译安装
- 基于AFNetworking3.0的网络封装
- iOS 网络与多线程--5.异步Post方式的网络请求(非阻塞)
- Nginx实现多域名证书HTTPS
- HTTP 2.0 协议详解