2

我在 C 函数中实现了一些东西,我想使用 NSTimer 方法调用另一个 c 方法,但选择器不起作用,也没有调用 self 方法。怎么能这样做?

 [NSTimer scheduledTimerWithTimeInterval:900 target:self selector:@selector(prepareToUploadLog()) userInfo:nil repeats:YES];

void prepareToUploadLog(void) 是另一个函数

4

1 回答 1

1

根据以下文件scheduledTimerWithTimeInterval

aSelector:定时器触发时发送给目标的消息。选择器必须对应于返回 void 并采用单个参数的方法。计时器将自己作为参数传递给此方法。

因此,您不能使用 C 函数,而必须添加一个包装 C 函数的 Objective C 方法。

- (void)prepareToUpload
{
    prepareToUploadLog();
}
于 2012-08-31T10:14:19.553 回答