Created
December 16, 2016 10:08
-
-
Save josephchang10/8ed6f5d0e0aa5c578a131e5f96e58552 to your computer and use it in GitHub Desktop.
Selector
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-(void) callMe { | |
//... | |
} | |
-(void) callMeWithParam:(id)obj { | |
//... | |
} | |
SEL someMethod = @selector(callMe); | |
SEL anotherMethod = @selector(callMeWithParam:); | |
// 或者也可以使用 NSSelectorFromString | |
// SEL someMethod = NSSelectorFromString(@"callMe"); | |
// SEL anotherMethod = NSSelectorFromString(@"callMeWithParam:"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
一般为了方便,很多人会选择使用
@selector
,但是如果要追求灵活的话,可能会更愿意使用NSSelectorFromString
的版本——因为我们可以在运行时动态生成字符串,从而通过方法的名字来调用到对应的方法。