0

Have basically two view controllers oneviewcontroller and mainviewcontroller. In oneviewcontroller defined myTimer. In mainviewcontroller i m trying to pause and resume myTimer using UIButton. But getting message No Known class method for selector 'myTimer'

In OneViewController defined NSTimer as myTimer

@property (nonatomic, retain) NSTimer *myTimer;

@synthesize myTimer;

- (void)viewDidLoad {

[self myTimerMethod];

[super viewDidLoad];

}


- (void)myTimerMethod{

 NSLog(@"myTimerMethod is Called");

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

}

- (void)updateView:(NSTimer *)theTimer
 {
 if  (index < [textArray count])
 {

  self.textView.text = [self.textArray objectAtIndex:index];
  self.imageView.image = [self.imagesArray objectAtIndex:index];
  index++;
  }else{

  index = 0;

  }

I m trying to pause and resume myTimer from mainviewcontroller

In mainviewcontroller.h

   @class OneViewController;

   @property (strong, nonatomic) OneViewController *oneviewcontroller;
   @synthesize oneviewcontroller = _oneviewcontroller;

  -(void)playpauseAction:(id)sender {

   if([audioPlayer isPlaying])
    {
    [sender setImage:[UIImage imageNamed:@"music.png"] forState:UIControlStateNormal];

    [audioPlayer pause];

    [[OneViewController myTimer] invalidate];    **\\No Known class method for selector 'myTimer'**



    }else{

    [sender setImage:[UIImage imageNamed:@"audiostop.png"] forState:UIControlStateNormal];

    [audioPlayer play];

    [[OneViewController myTimer] fire];  **\\No Known class method for selector 'myTimer'**


    if(isFirstTime == YES)
    {
        self.timer = [NSTimer scheduledTimerWithTimeInterval:06.0
                                                      target:self
                                                    selector:@selector(displayviewsAction:)
                                                    userInfo:nil
                                                     repeats:NO];
        isFirstTime  = NO; } } }

how can i fix this error.

Thanks for help.

4

1 回答 1

0

而不是 [[OneViewController myTimer] invalidate];使用[self.oneviewcontroller.myTimer invalidate];

此外,在 OneViewController 实现中,而不是myTimer = [NSTimer scheduledTimerWithTimeInterval:.....使用self.myTimer = [NSTimer scheduledTimerWithTimeInterval:.....

于 2013-02-21T21:58:59.987 回答