Thêm vào những gì đã được nói, nếu bạn muốn vượt qua một đối số duy nhất để MyFunc, cuộc gọi có thể được sửa đổi như sau
[self performSelector:@selector(showNote:) withObject:@"S" afterDelay:1.0];
và nếu bạn cần gọi phương thức lấy nhiều hơn 1 đối số, bạn có thể thực hiện điều đó bằng cách sử dụng lời gọi như được hiển thị trong đoạn mã sau -
SEL selector = @selector(nextPicture:);
NSMethodSignature *signature = [[self class] instanceMethodSignatureForSelector:selector];
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:signature];
[invocation setSelector:selector];
//Set the arguments
[invocation setTarget:self];
NSString* str = [imageNames objectAtIndex:1];
[invocation setArgument:&str atIndex:2];
[NSTimer scheduledTimerWithTimeInterval:5.0f invocation:invocation repeats:NO];
Nguồn
2013-05-07 07:03:48
thanks. cũng quan tâm: + (void) cancelPreviousPerformRequestsWithTarget: (id) aTarget selector: (SEL) đối tượng aSelector: (id) anArgument –
Đoạn mã trên có lỗi, sau khi cuộc gọi chọn không cần thiết cho các phương thức không có đối số. [self performSelector: @selector (myFunc) withObject: nil afterDelay: 5.0]; – archieoi