[英]Issues with NSInvocation NSTimer and NSMethodSignature
我試圖獲得一個按鈕來創建一個NSTimer,然后調用一個函數(refreshView)來刷新UI元素,但我遇到了問題,我不確定問題所在。 方法簽名是錯誤的嗎? 或者我是否將NSRunLoop部分弄錯了? 還是只是可怕的基地? 任何幫助表示贊賞。
-(IBAction)reload:(id)sender{
NSInvocation *displayInvocation = [NSInvocation invocationWithMethodSignature:[self methodSignatureForSelector:@selector(refreshView)]];
[displayInvocation setTarget:self];
NSTimer *slideShowTimer = [NSTimer scheduledTimerWithTimeInterval:5.0
invocation:displayInvocation
repeats:YES];
[slideShowTimer fire];
NSRunLoop * a = [NSRunLoop currentRunLoop];
[a addTimer:slideShowTimer forMode:NSRunLoopCommonModes];}
-(void)refreshView{
[slideshow1 displayWithView:MajorImageView topicLabel:TopicLabel];
}
你的代碼看起來很復雜。 你想(1)啟動定時器定期調用[refreshView],或者(2)稍后調用它。
對於(1),只需設置一個計時器,
[NSTimer scheduledTimerWithTimeInterval:(NSTimeInterval)seconds
target:(id)target
selector:(SEL)aSelector
userInfo:(id)userInfo
repeats:(BOOL)repeats]
無需使用方法調用,目標/操作就足夠了
對於(2),如果你想稍后再打電話,
[NSObject performSelector:(SEL)aSelector
withObject:(id)anArgument
afterDelay:(NSTimeInterval)delay]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.