gpt4 book ai didi

ios - NSTimer 有错误消息?

转载 作者:行者123 更新时间:2023-11-29 03:41:03 24 4
gpt4 key购买 nike

我正在尝试实现一个从 5 秒开始倒计时的 NSTimer。但我收到消息“选择器 ScheduledTimerWithTimeInterval:target:selector:userInfo:repeats..... 没有已知的类方法”我错过了什么?如果您查看 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];

<---选择器没有类方法scheduledTimerWithTimeInterval: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];

}

最佳答案

您在方法调用中将“target”错误拼写为“taget”。做:

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

相反。

关于ios - NSTimer 有错误消息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18439984/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com