最近在ios8时,发现如下报错:
Too many arguments to function call, expected 0, have 3
解决方法
((void (*)(id, SEL, id))(void *) objc_msgSend)((id)[Tools class], sel, @"参数"); objc_msgSend(receiver, selector, arg1, arg2, ...) 参数:receiver 接受对象 selector 方法选择器 arge1 参数 例如: 创建类 Tools .h中有个弹窗方法 需要传人参数str #import <Foundation/Foundation.h> @interface Tools : NSObject +(void)alertWithString:(NSString *)str; @end.m #import "Tools.h" @implementation Tools +(void)alertWithString:(NSString *)str { UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"提示" message:str delegate:nil cancelButtonTitle:@"确定" otherButtonTitles: nil]; [alert show]; } @end 其他类中调用 - (instancetype)init { self = [super init]; if (self) { [Tools alertWithString:@"111"]; SEL sel = @selector(alertWithString:); ((void (*)(id, SEL, id))(void *) objc_msgSend)((id)[Tools class], sel, @"你好runtime"); } return self; }最终效果为 技术有限 如有什么不对的地方 希望大牛 能多多指导!!!!
