13th Thu
その場で関数ポインタ型にキャストする方法
Objective-CでMethodのIMPを取得して呼び出す場合に、
正しい関数プロトタイプの関数ポインタにキャストする必要がありますが、
typedefなどを使わずにその場で目的の関数ポインタ型にキャスト
する方法を紹介します。
objective-c>>
SEL selector = @selector(drawRect:);
Method method = class_getInstanceMethod([UISearchBar class], selector);
IMP drawRect = method_getImplementation(method);
((void(*)(id, SEL, CGRect))drawRect)(self, selector, rect);
<<--
こんな感じにすればOkです。
posted by
genki on Thu 13 Nov 2008 at 01:12 with 0 comments