1
사용자 정보가 매개 변수를 전달하는 데 사용되지만 둘 이상을 전달하는 방법을 알고 있습니까?'scheduledTimerWithTimeInterval : target : selector : userInfo : repeats :'
나는 객체를 사용해야한다고 생각하지만, 객관적으로 매우 새롭기 때문에 나는 이것이 옳은지, 어떻게 움직이는 지 정말로 모른다.
감사합니다.
사용자 정보가 매개 변수를 전달하는 데 사용되지만 둘 이상을 전달하는 방법을 알고 있습니까?'scheduledTimerWithTimeInterval : target : selector : userInfo : repeats :'
나는 객체를 사용해야한다고 생각하지만, 객관적으로 매우 새롭기 때문에 나는 이것이 옳은지, 어떻게 움직이는 지 정말로 모른다.
감사합니다.
NSArray
또는 NSDictionary
래퍼 객체를 만들고 전달해야하는 여러 객체가 있고 userInfo
에 래퍼 객체를 전달하십시오. 리시버에서 랩퍼 오브젝트에서 오브젝트를 검색하십시오.
예제 코드 :
국가 번호 :
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"];
// ...
}