Objective-CでMethodのIMPを取得して呼び出す場合に、 正しい関数プロトタイプの関数ポインタにキャストする必要がありますが、 typedefなどを使わずにその場で目的の関数ポインタ型にキャスト する方法を紹介します。

   1  SEL selector = @selector(drawRect:);
   2  Method method = class_getInstanceMethod([UISearchBar class], selector);
   3  IMP drawRect = method_getImplementation(method);
   4  ((void(*)(id, SEL, CGRect))drawRect)(self, selector, rect);

こんな感じにすればOkです。

posted by Png genki on Thu 13 Nov 2008 at 01:15

Comments:

or Preview
Social Bookmarks
  • Delicious
  • B_entry1027
  • Clip_16_12_w
Services from s21g
twpro(ツイプロ)
Twitterプロフィールを快適検索
地価2009
土地の値段を調べてみよう
MyRestaurant
自分だけのレストラン手帳
Formula
ブログに数式を埋め込める数式コミュニティ