2012-03-01 65 views

回答

4

用你需要傳遞的多個對象創建一個包裝對象或NSDictionary並傳遞userInfo中的包裝對象。在接收器上從包裝器對象中檢索對象。

使用的NSDictionary爲包裝

示例代碼:

呼叫號碼:

NSString *obj1 = @"string1"; 
NSString *obj2 = @"string2"; 
NSDictionary *wrapper = [NSDictionary dictionaryWithObjectsAndKeys:obj1, @"Object1", obj2, @"Object2", nil]; 
[NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(timerFireMethod:) userInfo:wrapper repeats:NO]; 

接收定時器的代碼:

- (void)timerFireMethod:(NSTimer*)theTimer { 
    NSDictionary *wrapper = (NSDictionary *)[theTimer userInfo]; 
    NSString * obj1 = [wrapper objectForKey:@"Object1"]; 
    NSString * obj2 = [wrapper objectForKey:@"Object2"]; 
    // ... 
}