Last Update: 2010/07/19 16:35
使用NSObject 的 performSelector 來調用函式
SEL 是一個指標結構,用來儲存函式指標
typedef struct { int code; NSString *message; }PassingData; - (void)invokedMethod : (id)sender : (PassingData*)msg{ NSLog(@"%d : %@", msg->code, msg->message); } - (void)execInvoke : (id)sender : (SEL)method{ PassingData *pd = malloc(sizeof(PassingData)); pd->code = 3; pd->message = @"QWERT"; [sender performSelector:method withObject:sender withObject:(id)pd]; free(pd); } - (void)applicationDidFinishLaunching:(NSNotification *)aNotification { // Insert code here to initialize your application [self execInvoke:self :@selector(invokedMethod::)]; }
沒有留言:
張貼留言