問題について助けが必要です。
目標
ビューを読み込んだ後、NSTimers を使用していくつかのずらしたアニメーション イベントを発生させる iOS ブック アプリをまとめています。これを行うのに役立つMethodCallerWithTimerクラスを作成しました(コードは下部にあります)。
これまでの解決方法MethodCallerWithTimer
クラス
を使用する場合、objectOwningMethod を UIViewController サブクラス オブジェクト (本のページ) として割り当て、そのメソッドをそのクラスのインスタンス メソッドとして割り当てます。これは私が割り当てたメソッドの例です - 画面上のいくつかのアートワークをオンにするだけです:
- (void) playEmory {
[emoryRedArt setHidden:NO];
}
私の問題
複数のMethodCallerWithTimerインスタンスを作成し、ビューをロードしてそれらをすべて開始すると、最初のイベントしか発生しません。他のどのタイマーも、ターゲット メソッドを呼び出しません。NSRunLoop に何を求めているのか、または同様のことを理解していないと思われます。
何かご意見は?
ここに私のMethodCallerWithTimerクラスがあります:
@interface MethodCallerWithTimer : NSObject {
NSTimer * timer;
NSInvocation * methodInvocationObject;
NSNumber * timeLengthInMS;
}
- (id) initWithObject: (id) objectOwningMethod AndMethodToCall: (SEL) method;
- (void) setTime: (int) milliseconds;
- (void) startTimer;
- (void) cancelTimer;
@end
そして実装:
#import "MethodCallerWithTimer.h"
@implementation MethodCallerWithTimer
- (id) initWithObject: (id) objectOwningMethod AndMethodToCall: (SEL) method {
NSMethodSignature * methSig = [[objectOwningMethod class] instanceMethodSignatureForSelector:method];
methodInvocationObject = [NSInvocation invocationWithMethodSignature:methSig];
[methodInvocationObject setTarget:objectOwningMethod];
[methodInvocationObject setSelector:method];
[methSig release];
return [super init];
}
- (void) setTime: (int) milliseconds {
timeLengthInMS = [[NSNumber alloc] initWithInt:milliseconds];
}
- (void) startTimer {
timer = [NSTimer scheduledTimerWithTimeInterval:([timeLengthInMS longValue]*0.001) invocation:methodInvocationObject repeats:NO];
}
- (void) cancelTimer {
[timer invalidate];
}
-(void) dealloc {
[timer release];
[methodInvocationObject release];
[timeLengthInMS release];
[super dealloc];
}
@end