免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1306 | 回复: 0
打印 上一主题 下一主题

iPhone开发, NSInvocation的用法 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-12-22 08:51 |只看该作者 |倒序浏览

目的,给timer触发的函数传递参数。


-(void) startCheckTimer: (PackageInfo *) package

{

    DeviceInfo *deviceInfo = package.deviceInfo;


    NSTimeInterval timeInterval = [self getTimeIntervalByConnectionType: deviceInfo.connectionType];

    

    // 使用 NSInvocation 传递除 NSTimer 本身之外的其他参数

    SEL selector = @selector(checkPackageStatus:); 

    NSMethodSignature *signature = [TestUdpClientAppDelegate instanceMethodSignatureForSelector: selector]; 

    NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:signature];


    [invocation setTarget: self];           // 0

    [invocation setSelector: selector];     // 1

    [invocation setArgument: &package atIndex: 2]; // 2


    // 指数在01表示隐藏的论据自我和_cmd,分别,你应该设置这些值直接与setTarget:和setSelector:方法。 

    // 2,对于使用指数通常在消息传递的参数更大。


    [NSTimer scheduledTimerWithTimeInterval: timeInterval invocation:invocation repeats: NO]; 

}

您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP