NSTimer с сообщением об ошибке?

Я пытаюсь реализовать обратный отсчет NSTimer с 5 секунд. Но я получаю сообщение «Нет известного метода класса для селектора scheduleTimerWithTimeInterval: target: selector: userInfo: repeatats .....» Что мне не хватает? Если вы посмотрите на нижнюю часть MTPopupWindow.m в методе -void (showInView), вы найдете код, в котором возникает ошибка.

С Уважением

MTPopupWindow.h

@class MTPopupWindow;

@protocol MTPopupWindowDelegate <NSObject>
@optional
- (void) willShowMTPopupWindow:(MTPopupWindow*)sender;
- (void) didShowMTPopupWindow:(MTPopupWindow*)sender;
- (void) willCloseMTPopupWindow:(MTPopupWindow*)sender;
- (void) didCloseMTPopupWindow:(MTPopupWindow*)sender;
@end

@interface MTPopupWindow : UIView

+(MTPopupWindow*)showWindowWithHTMLFile:(NSString*)fileName;
+(MTPopupWindow*)showWindowWithHTMLFile:(NSString*)fileName insideView:(UIView*)view;
- (void)timerFireMethod; 
-(void)showInView:(UIView*)v;
+(void)setWindowMargin:(CGSize)margin;

@property (strong, nonatomic) NSString* fileName;
@property (strong, nonatomic) UIWebView* webView;
@property (weak, nonatomic) id <MTPopupWindowDelegate> delegate;
@property (nonatomic) BOOL usesSafari;
@property (nonatomic, retain) NSTimer* timer;
@end

MTPopupWindow.m

#import "MTPopupWindow.h"
#import "QuartzCore/QuartzCore.h"
#define kCloseBtnDiameter 30
#define kDefaultMargin 18
static CGSize kWindowMarginSize;

@interface MTPopupWindow() <UIWebViewDelegate>
{
UIView* _dimView;
UIView* _bgView;
UIActivityIndicatorView* _loader;
NSTimer *timer;
}
@end

@interface MTPopupWindowCloseButton : UIButton
+ (id)buttonInView:(UIView*)v;
@end

@interface UIView(MTPopupWindowLayoutShortcuts)
-(void)replaceConstraint:(NSLayoutConstraint*)c;
-(void)layoutCenterInView:(UIView*)v;
-(void)layoutInView:(UIView*)v setSize:(CGSize)s;
-(void)layoutMaximizeInView:(UIView*)v withInset:(float)inset;
-(void)layoutMaximizeInView:(UIView*)v withInsetSize:(CGSize)insetSize;
@end

@implementation MTPopupWindow

@synthesize fileName = _fileName;
@synthesize webView = _webView;
@synthesize usesSafari = _usesSafari;
@synthesize delegate = _delegate;
@synthesize timer;

-(void)showInView:(UIView*)v
{
.......
self.timer = [NSTimer scheduledTimerWithTimeInterval:5 taget:self selector:@selector(timerFireMethod:) userInfo:nil repeats:NO];  

‹--- Нет метода класса для селектора scheduleTimerWithTimeInterval: target: selector ....

}

-(void)timerFireMethod:(NSTimer *)theTimer{

NSLog(@"bla bla time is out");
MTPopupWindowCloseButton* btnClose = [MTPopupWindowCloseButton buttonInView:self];
[btnClose addTarget:self action:@selector(closePopupWindow) forControlEvents:UIControlEventTouchUpInside];

}

person Jesper Martensson    schedule 26.08.2013    source источник
comment
Если вы просто хотите запустить это один раз, вам следует использовать [self performSelector: @selector (YourMethod) withObject: nil afterDelay: 5];   -  person Son Nguyen    schedule 26.08.2013


Ответы (2)


Вы неправильно написали target как taget в вызове метода. Делать:

self.timer = [NSTimer scheduledTimerWithTimeInterval:5 target:self selector:@selector(timerFireMethod:) userInfo:nil repeats:NO];

Вместо.

person Carl Veazey    schedule 26.08.2013
comment
Ваше здоровье! Самые маленькие ошибки часто оказываются самыми тяжелыми! - person Jesper Martensson; 26.08.2013

В файле .h используется следующий метод: - (void) timerFireMethod; Но в селекторе есть: timerFireMethod: С ":" в конце, но нет параметра, вот почему.

Ваше определение между файлом h и файлом m не является согласованием. Исправьте метод timerFireMethod.

person Son Nguyen    schedule 26.08.2013
comment
Это может вызвать предупреждение о неполной реализации, но не эту конкретную ошибку. Селектор, указанный для таймера, такой же, как реализованный, поэтому он также не должен вызывать сбой во время выполнения. - person Carl Veazey; 26.08.2013
comment
Вы видите сообщение об ошибке? Нет известного метода класса для селектора - person Son Nguyen; 26.08.2013