objc_msgSend

- (void)runTimeClicked
{
    //objc_msgSend(self,@selector(testRuntime));
    SEL testFunc = NSSelectorFromString(@"testRuntime");
    
    //ios8下特殊写法
    ((void(*)(id,SEL, id,id))objc_msgSend)(self, testFunc, nil, nil);
}
 
 
- (void)testRuntime
{
    NSLog(@"-----timeruntiem---");
}

示例:

NSString* tmpStr=@"Orientation";
        UIInterfaceOrientation ifo=[[UIApplication sharedApplication] statusBarOrientation];
        ((void(*)(id,SEL,UIInterfaceOrientation,BOOL))objc_msgSend)([UIDevice currentDevice],NSSelectorFromString([NSString stringWithFormat:@"set%@:animated:",tmpStr]),ifo,NO);

你可能感兴趣的:(objc_msgSend)