zoukankan      html  css  js  c++  java
  • iOS 网络与多线程--7.Performselector消息处理方法

    创建一个IOSApp类

    IOSApp.h文件

     1 #import <Foundation/Foundation.h>
     2 
     3 @interface IOSApp : NSObject
     4 
     5 // 1.添加一个无参数的方法
     6 -(void)printInfomation;
     7 
     8 // 2.添加一个有参数的方法
     9 -(void)buyApp:(id)appName;
    10 
    11 @end

    IOSApp.m文件

     1 #import "IOSApp.h"
     2 
     3 @implementation IOSApp
     4 
     5 // 3.实现头文件中无参数的方法
     6 -(void)printInfomation
     7 {
     8     NSLog(@"Xcode Interactive Tutorials");
     9 }
    10 
    11 // 4.实现头文件中带有参数的方法
    12 -(void)buyApp:(id)appName
    13 {
    14     NSLog(@"Buy the App%@",appName);
    15 }
    16 
    17 @end

     ViewController.m 文件

     1 #import "ViewController.h"
     2 // 5.导入钢材创建的类的头文件
     3 #import "IOSApp.h"
     4 
     5 
     6 @interface ViewController ()
     7 
     8 @end
     9 
    10 @implementation ViewController
    11 
    12 
    13 - (void)viewDidLoad {
    14     [super viewDidLoad];
    15     // Do any additional setup after loading the view, typically from a nib.
    16     
    17     // 6.初始化一个类对象
    18     IOSApp *app = [[IOSApp alloc] init];
    19     // 7.@selector()可以理解为取类方法的编号,它的行为基本可以等同c语言中的函数指针,它的结果是SEL类型。
    20     SEL method = @selector(printInfomation);
    21     // 8.respondsToSelector()方法,用来判断是否有,以某个名字命名的方法。
    22     if ([app respondsToSelector:method]){
    23         
    24         // 9.performSelector是由运行时系统负责去找方法的,在编译时不做任何校验
    25         // 调用方法
    26         [app performSelector:method];
    27     }
    28     
    29     SEL method2 = @selector(buyApp:);
    30     if ([app respondsToSelector:method2]) {
    31         // 调用方法
    32         [app performSelector:method2 withObject:(@"Photoshop Interactive Tutorials")];
    33     }
    34 }
    35 
    36 
    37 
    38 - (void)didReceiveMemoryWarning {
    39     [super didReceiveMemoryWarning];
    40     // Dispose of any resources that can be recreated.
    41 }
    42 
    43 @end
  • 相关阅读:
    访问 http://localhost:8081对 flink 集群和任务进行监控管理
    Flink之流处理WordCount
    Flink之批处理WordCount
    为什么说JAVA中runnable接口的run方法运行在子线程?
    Java中的字符输入输出流练习
    在JAVA中实现文件读写练习
    JAVA自定义异常使用方法
    三种二叉树遍历的非递归算法
    C编译错误:Main.c:4:5: error: variably modified ‘f’ at file scope int f[maxn];
    中序+先序构造二叉树,后序遍历
  • 原文地址:https://www.cnblogs.com/-jpp/p/5020807.html
Copyright © 2011-2022 走看看