我正在进行块编程,我已经创建了一个块。
void(^paint)(void)=^(void){
NSLog(@"Process ");
};
现在我想用下面的NSinvocation和NSMethodSignatiureas创建一个ntimer。
void(^startPainting)(id)=^(id self){
**SEL selectorToCall=@selector(paint());**
NSMethodSignature *methodSignature=[[self class] instanceMethodSignatureForSelector:selectorToCall];
NSInvocation *invocation=[NSInvocation invocationWithMethodSignature:methodSignature];
[invocation setSelector:selectorToCall];
[invocation setTarget:self];
[self setPaintTimer:[NSTimer scheduledTimerWithTimeInterval:1.0 invocation:invocation repeats:YES] ];
// self.paintTimer=[NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(paint:) userInfo:nil repeats:YES];
};
这里的问题是我想发送和块油漆到SEL。因为当前语句给出了错误。请告诉我哪里做错了。我如何将这个块传递给这个选择器?
SEL selectorToCall=@selector(paint());
您可以使用调度队列代替选择器,其工作方式相同,并且比触发选择器造成的延迟要好得多:
dispatch_async(dispatch_get_main_queue(), paint);
的问候Heider