//封装invacation可以调用多个参数的方法
-(void)invacation
{
//1.创建一个MethodSignature,签名中保存了方法的名称,参数和返回值
//这个方法属于谁,那么就用谁来进行创建
//注意:签名一般是用来设置参数和获得返回值的,和方法的调用没有太大的关系
NSMethodSignature *signature = [ViewController instanceMethodSignatureForSelector:@selector(callWithNumber:andContext:withStatus:)]; /*注意不要写错了方法名称
// NSMethodSignature *signature = [ViewController methodSignatureForSelector:@selector(call)];
*/ //2.通过MethodSignature来创建一个NSInvocation
//NSInvocation中保存了方法所属于的对象|方法名称|参数|返回值等等
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:signature]; /*2.1 设置invocation,来调用方法*/ invocation.target = self;
// invocation.selector = @selector(call);
// invocation.selector = @selector(callWithNumber:);
// invocation.selector = @selector(callWithNumber:andContext:);
invocation.selector = @selector(callWithNumber:andContext:withStatus:); NSString *number = @"10086";
NSString *context = @"下课了";
NSString *status = @"睡觉的时候"; //注意:
//1.自定义的参数索引从2开始,0和1已经被self and _cmd占用了
//2.方法签名中保存的方法名称必须和调用的名称一致
[invocation setArgument:&number atIndex:2];
[invocation setArgument:&context atIndex:3];
[invocation setArgument:&status atIndex:4]; /*3.调用invok方法来执行*/
[invocation invoke];
}

NSInvocation的基本使用的更多相关文章

  1. Objective-C中NSInvocation的使用

    OC中调用方法某个对象的消息呦两种方式: #1. performanceSelector: withObject: #2. NSInvocation. 第一个PerformaceSelector比较常 ...

  2. iOS开发——网络篇——UIWebview基本使用,NSInvocation(封装类),NSMethodSignature(签名),JavaScript,抛异常,消除警告

    一.UIWebView简介 1.UIWebView什么是UIWebViewUIWebView是iOS内置的浏览器控件系统自带的Safari浏览器就是通过UIWebView实现的 UIWebView不但 ...

  3. NSInvocation

    NSInvocation 基本简介 NSInvocation是一个静态描绘的OC消息,也就是说,它是一个动作,这个动作可以变成一个对象.NSInvocation对象在对象和对象之间和应用程序和应用程序 ...

  4. IOS NSInvocation用法简介

    IOS NSInvocation用法简介 2012-10-25 19:59 来源:博客园 作者:csj007523 字号:T|T [摘要]在 iOS中可以直接调用某个对象的消息方式有两种,其中一种就是 ...

  5. NSInvocation Basics

    In this article I'm going to cover the basics and usages of NSInvocation. What is NSInvocation? Appl ...

  6. NSInvocation的使用(转)

    转载自:http://www.cnblogs.com/pengyingh/articles/2359199.html http://blog.iosxcode4.com/?p=125 在 iOS中可以 ...

  7. ios NSMethodSignature and NSInvocation 消息转发

    1.首先获取消息转发时连个函数内部具体内容 MARK:这里是拿[@"xxxxx" length]调用拿来举例说明 (lldb) po signature <NSMethodS ...

  8. 利用NSInvocation对方法进行抽象,实现对方法的加锁

    我们在实际开发中须要对离散的方式加锁实现线程安全,当然我们有多种实现方式,这仅仅是当中一种,使用起来比較方便 + (id)performSelectorWithTarget:(id)target se ...

  9. iOS NSInvocation的学习

    用途: NSInvocation的作用和performSelector:withObject:的作用是一样的:用于iOS编程中调用某个对象的消息. performSelector:withObject ...

  10. 第16月第8天 NSInvocation存储 函数指针 va_arg lldb

    1.NSInvocation存储 -(void)setInvok:(id)target sel:(SEL)sel key:(id)key { if(!target) return; NSMethodS ...

随机推荐

  1. An Introduction to Measure Theory and Probability

    目录 Chapter 1 Measure spaces Chapter 2 Integration Chapter 3 Spaces of integrable functions Chapter 4 ...

  2. 造轮子-strace(二)实现

    这一篇文章会介绍strace如何工作,再稍微深入介绍一下什么是system call.再介绍一下ptrace.wait(strace依赖的system call).最后再一起来造个轮子,动手用代码实现 ...

  3. Docker_安装和卸载(2)

    1.检查是否安装docker docker -v 下图为已安装docker的结果 下图为未安装docker的结果 2.卸载docker 查看已安装的版本 yum list installed | gr ...

  4. vue3.0 没有 vue.condig.js 解决

    第一次用 vue3.0 ,发现没有vue.config.js  ,只有一个babel.config.js 怎么办? 需要在根目录手动添加一个即可,如下 相关的配置说明 module.exports = ...

  5. 【从小白到专家】Istio技术实践专题(四):应用接入Istio的正确姿势

    上一篇文章中,我们介绍了Istio针对单集群的三种主流部署安装方式:使用Istioctl安装.使用Helm自定义安装.独立Operator安装.本文将向大家介绍kubernetes中的应用接入Isti ...

  6. 面试官问,Redis 是单线程还是多线程?我懵了

    我们平时看到介绍 Redis 的文章,都会说 Redis 是单线程的.但是我们学习的时候,比如 Redis 的 bgsave 命令,它的作用是在后台异步保存当前数据库的数据到磁盘,那既然是异步了,肯定 ...

  7. TexStudio中Bibtex使用

    TexStudio中Bibtex使用 1.首先在百度文库中找到相应的参考文献: 2.建立bibfile.bib文件,放在和.tex同一目录下,将上面页面的结果考入该文件,注意其中第一行中的Tuan20 ...

  8. RichTextBox单独设置文字颜色

    richTextBox1.Select(index, "str1".Length); richTextBox1.SelectionColor = Color.Red;

  9. C# 计算三角形和长方形 周长面积

    编写一个控制台应用程序,输入三角形或者长方形边长,计算其周长和面积并输出. 代码如下: using System; using System.Collections.Generic; using Sy ...

  10. manjaro20安装teamviewer出现sudo teamviewer –daemon start无响应

    问题 https://www.randomhacks.co.uk/the-teamviewer-daemon-is-not-running-please-start-the-daemon-ubuntu ...