我在学习有关NSTimer和读完文档后,我做了这个简单的测试。我的理解是,当我在main中调用viewDidLoad时,viewDidLoad应该在3.0秒后调用runTest - 但它不起作用。它编译罚款没有错误,但不会加载runTest(没有NSLog)请帮助...谢谢。简单的NSTimer测试不起作用
#import "MyClass.h"
#import <Foundation/Foundation.h>
int main (int argc, const char * argv[])
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
MyClass *trial = [[MyClass alloc]init];
[trial viewDidLoad]; ///// this should call viewDidLoad /////
[pool drain];
return 0;
}
#import <Foundation/Foundation.h>
@interface MyClass : NSObject {
NSTimer *aTimer;}
@property (nonatomic, retain) NSTimer *aTimer;
- (void)viewDidLoad;
- (void)runTest;
@end
#import "MyClass.h"
@implementation MyClass
@synthesize aTimer;
- (void)viewDidLoad {
aTimer = [NSTimer scheduledTimerWithTimeInterval:3.0 target:self selector:@selector(runTest) userInfo:nil repeats:NO];}
- (void) runTest {
NSLog(@"Working - runTest has loaded !");
aTimer = nil;
}
@end
你确定你在调用viewDidLoad吗? – jbat100