如何將一個方法作爲參數傳遞給另一個方法?我正在跨班級做這個。Objective-C傳遞方法作爲參數
A類:
+ (void)theBigFunction:(?)func{
// run the func here
}
B類:
- (void)littleBFunction {
NSLog(@"classB little function");
}
// somewhere else in the class
[ClassA theBigFunction:littleBFunction]
C類:
- (void)littleCFunction {
NSLog(@"classC little function");
}
// somewhere else in the class
[ClassA theBigFunction:littleCFunction]
您通過選擇器s,這是一個類似的問題: http://stackoverflow.com/questions/519600/is-it-possible-to-pass-a-method-as-an-argument-in-objective-c – utahwithak