0

我有 one.m 类,并且在 one.m 类中定义了 NSTimer

myTimer = [NSTimer scheduledTimerWithTimeInterval:2.6
                                 target:self
                               selector:@selector(updateView:)
                               userInfo:nil
                                repeats:YES];

我如何在 mainviewcontroller 中访问这个 NSTimer 来暂停和恢复它。

4

1 回答 1

0

您可以将计时器设为属性,然后从MainViewController类中访问它。像这样

@interface One: UIDelegate {
    //variables
}
@property(nonatomic, retain) NSTimer* myTimer;

@implementation One
@synthesize myTimer;
//other

@implementation MainViewController
One *one = [[One alloc]init];
one.myTimer; //now you can access the timer
于 2013-02-20T19:54:21.990 回答