IOS系列-responseToSelector
来源:互联网 发布:excelplus电子表格mac 编辑:程序博客网 时间:2024/06/05 22:42
转载 :http://blog.csdn.net/chengyingzhilian/article/details/7930398
SEL sel = @selector (start:) ; // 指定action
if ([obj respondsToSelector:sel])
{ //判断该对象是否有相应的方法
[obj performSelector:sel withObject:self]; //调用选择器方法
}
使用[[UIApplication sharedApplication] keyWindow]查找应用程序的主窗口对象
respondsToSelector判断是否实现了某方法
Tester.h
#import <Foundation/Foundation.h>
@interface Tester : NSObject {
}
-(void) test:(NSString*) msg;
-(void) notImp;
@end
Tester.m
#import "Tester.h"
@implementation Tester
-(void) test:(NSString*) msg
{
NSLog(@"%@", msg);
}
@end
main.m
#import <Foundation/Foundation.h>
#import "Tester.h"
int main (int argc, const char * argv[])
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
id tester = [[Tester alloc] init];//注意,这里使用id
SEL testSelector = @selector(test:);
SEL notImpSelector = @selector(notImp:);
if([tester respondsToSelector:testSelector])
{
//tester.m中实现了test方法
[tester test:@"invoke test method"];
}
if([tester respondsToSelector:notImpSelector])
{
//test.m中没有实现此主就去
[tester notImp];
}
[pool drain];
return 0;
}
0 0
- IOS系列-responseToSelector
- ios 系列
- iOS系列
- iOS 控件系列:UIActionSheet
- iOS性能优化系列
- iOS 开发系列教程
- iOS面试题系列:
- iOS性能优化系列
- iOS安全系列汇总
- iOS 安全攻防系列
- iOS安全系列汇总
- iOS安全系列汇总
- IOS开发工具系列
- ios bug系列
- iOS性能优化系列
- iOS性能优化系列
- iOS性能优化系列
- iOS性能优化系列
- yii框架-yii2分页的使用与扩展(十五)
- Java实验(5) 最大子方阵
- require.js的用法
- Android 屏幕dp px换算
- android中的安装删除程序的流氓方法
- IOS系列-responseToSelector
- Java Socket简单例子、readLine()、readUTF()
- Linux PATH 设置
- 机器学习模型性能测试结果(R或者python),逻辑回归的测试结果没有添加
- leetcode_c++:Game of Life(289)
- Java项目导出源代码jar包在Eclipse中查看中文注释乱码的问题
- Python的method, class method, static method
- Android平台证件识别系统
- JQ-事件-1