.h ファイルに次のコードがあります。
#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>
#import <AVFoundation/AVFoundation.h>
#import <MapKit/MapKit.h>
@interface LandingController : UIViewController<CLLocationManagerDelegate> {
CLLocationManager *LocationManager;
AVAudioPlayer *audioPlayer;
}
@property (nonatomic, retain) NSTimer *messageTimer;
- (IBAction)LoginButton:(id)sender;
@end
.m ファイルに次のコードがあります。
@interface LandingController ()
@end
@implementation LandingController
@synthesize messageTimer;
- (void)checkForMessages
{
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"BINGO:"
message:@"Bingo This Works"
delegate:nil
cancelButtonTitle:@"Okay"
otherButtonTitles:nil];
[alert show];
}
- (IBAction)LoginButton:(id)sender {
if ([UserType isEqualToString:@"Owner"]) {
if (messageTimer){
[self.messageTimer invalidate];
self.messageTimer = nil;
}
} else {
if (!messageTimer){
self.messageTimer = [NSTimer scheduledTimerWithTimeInterval:10.0
target:self
selector:@selector(checkForMessages)
userInfo:nil
repeats:YES];
}
}
}
@end
しかし、無効化を呼び出したときにタイマーが停止したくありません。
LoginButton は 2 回だけ押されます。1 回は strResult が「Guard」に = であり、アプリケーションがそれを「所有者」に等しくなるように変更し、ユーザーが再度ログイン ボタンを押すため、複数を設定しているとは思えません。タイマー。
ログインボタンを押してタイマーを開始した後、別のビューにセグエしてから、セグエバックしてもう一度ログインボタンを押します。これは、タイマーを停止したいときです。しばらくビューを切り替えてから戻ってきたので、messageTimer を取得するために何か特別なことをする必要がありますか?
何か案は?
ありがとう!