2012-02-11 8 views
0

NSTimerを作成するボタンを取得しようとしていますが、UIエレメントを更新するために関数(refreshView)が呼び出されますが、問題が発生しています。メソッドのシグネチャは間違っていますか?またはNSRunLoopの部分が間違っていますか?それともそれはちょうど恐ろしいベースからですか?どんな助けもありがとうございます。NSInvocationの問題NSTimerとNSMethodSignature

-(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]; 
} 

答えて

2

あなたのコードは何のためにも非常に複雑です。 (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] 
+0

完全に明確にするには、 'scheduledTimer ... 'で作成されたタイマーが実行ループに_already_追加されていることを言及する必要があります。また、タイマーは 'fire'を送る必要はありません。 –

+0

ありがとう、それは今完璧に動作しています! –