NSDictionary* 変数 = [《NSTimer*》userInfo];このようにして取り出すことができます。今回は、@"msg"というキーの値を取り出して出力させています。ということは、NSTimer作成時に、NSDictionaryにこのキーの値を保管しておけばいい、ということになります。
※リストが表示されない場合
AddBlockなどの広告ブロックツールがONになっているとリストなどが表示されない場合があります。これらのツールをOFFにしてみてください。
※MyTestClass.h
#import <Foundation/Foundation.h>
@interface MyTestClass : NSObject {
int count;
int endcount;
}
+(MyTestClass*)myTestClassToEndCount:(int)n;
-(void)setEndCount:(int)n;
-(BOOL)checkEnd:(NSTimer*)t;
-(void)printMessage:(NSTimer*)t;
@end
※MyTestClass.m
#import "MyTestClass.h"
@implementation MyTestClass
+(MyTestClass*)myTestClassToEndCount:(int)n {
MyTestClass* obj = [[MyTestClass alloc] init];
[obj setEndCount:n];
return obj;
}
-(void)setEndCount:(int)n {
endcount = n;
}
-(void)printMessage:(NSTimer*)t {
id s = [[t userInfo] objectForKey:@"msg"];
NSLog(@"%@:%i",s,++count);
[self checkEnd:t];
}
-(BOOL)checkEnd:(NSTimer*)t {
BOOL flg = NO;
if (endcount == count){
NSLog(@"end.");
flg = YES;
[t invalidate];
}
return flg;
}
@end
| << 前へ | 次へ >> |