myTimer 在 OneViewController 中定义,我试图从 mainviewcontroller 使其无效并再次触发它,但它不起作用。我到底在这里缺少什么。
这是我的代码
OneViewController.h
@property (nonatomic, strong) NSTimer *myTimer;
OneViewController.m
@synthesize myTimer;
- (void)viewDidLoad
{
[super viewDidLoad];
[self myTimerMethod];}
- (void)myTimerMethod{
NSLog(@"myTimerMethod is Called");
self.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;
}
}
MainViewController.h
@class OneViewController;
@property (strong, nonatomic) OneViewController *oneviewcontroller;
MainViewController.m
@synthesize oneviewcontroller = _oneviewcontroller;
-(void)playpauseAction:(id)sender {
if([audioPlayer isPlaying])
{
[sender setImage:[UIImage imageNamed:@"music.png"] forState:UIControlStateNormal];
[audioPlayer pause];
[self.oneviewcontroller.myTimer invalidate];
}else{
[sender setImage:[UIImage imageNamed:@"audiostop.png"] forState:UIControlStateNormal];
[audioPlayer play];
[self.oneviewcontroller.myTimer fire];
if(isFirstTime == YES)
{
self.timer = [NSTimer scheduledTimerWithTimeInterval:06.0
target:self
selector:@selector(displayviewsAction:)
userInfo:nil
repeats:NO];
isFirstTime = NO; } } }
- (void)displayviewsAction:(id)sender{
OneViewController *oneviewcontroller = [[OneViewController alloc] init];
oneviewcontroller.view.frame = CGRectMake(0, 0, 320, 430);
CATransition *transitionAnimation = [CATransition animation];
[transitionAnimation setDuration:1];
[transitionAnimation setType:kCATransitionFade];
[transitionAnimation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]];
[self.view.layer addAnimation:transitionAnimation forKey:kCATransitionFade];
[self.view addSubview:oneviewcontroller.view];
}
感谢帮助。
谢谢。