将NSTimer从一个类访问到另一个类

时间:2013-02-20 19:50:51

标签: cocoa-touch ios6

我有班级one.m,在班级one.m中定义了NSTimer

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

如何在mainviewcontroller中访问此NSTimer以暂停和恢复它。

1 个答案:

答案 0 :(得分: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