我设置了一个计时器来重置对象的属性:
- (IBAction)open:(id)sender {
int viewID = ((UIButton*)sender).tag;
for (int i=0; i<[self.webViews count]; i++) {
WebViewController* page = [self.webViews objectAtIndex:i];
if (page.loadFinished == NO) {
[page.webView stopLoading];
[NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(setLoadingNotFinished:) userInfo:page repeats:NO];
}
}
- (void) setLoadingNotFinished:(WebViewController*)page {
page.loadFinished = NO;
}
当输入setLoadingNotFinished方法时,发生此崩溃:
2011-04-25 04:34:22.358 MyApp[7823:207] -[__NSCFTimer setLoadFinished:]: unrecognized selector sent to instance 0x4b203d0
2011-04-25 04:34:22.360 MyApp[7823:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFTimer setLoadFinished:]: unrecognized selector sent to instance 0x4b203d0'
*** Call stack at first throw:
(
0 CoreFoundation 0x00dca5a9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x00f1e313 objc_exception_throw + 44
2 CoreFoundation 0x00dcc0bb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x00d3b966 ___forwarding___ + 966
4 CoreFoundation 0x00d3b522 _CF_forwarding_prep_0 + 50
5 MyApp 0x00003a42 -[MainGridController setLoadingNotFinished:] + 66
6 Foundation 0x007ba749 __NSFireTimer + 125
7 CoreFoundation 0x00dab8c3 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 19
8 CoreFoundation 0x00dace74 __CFRunLoopDoTimer + 1220
9 CoreFoundation 0x00d092c9 __CFRunLoopRun + 1817
10 CoreFoundation 0x00d08840 CFRunLoopRunSpecific + 208
11 CoreFoundation 0x00d08761 CFRunLoopRunInMode + 97
12 GraphicsServices 0x010021c4 GSEventRunModal + 217
13 GraphicsServices 0x01002289 GSEventRun + 115
14 UIKit 0x0002ac93 UIApplicationMain + 1160
15 MyApp 0x000027e9 main + 121
16 MyApp 0x00002765 start + 53
)
terminate called after throwing an instance of 'NSException'
为什么会发生这种崩溃?
我不明白为什么找不到选择器。
设置了loadFinished属性,即使对该属性的第一个测试在调用NSTimer方法之前也可以运行,并且我在许多地方都使用了此属性。
页面在计时方法中不为零。
self.webViews是保留的NSMutableArray。
最佳答案
请再次检查代码。我纠正了。它有语法错误。
以下应解决此问题:- (void) setLoadingNotFinished:(NSTimer *)myTimer {
WebViewController *page = (WebViewController *)[myTimer userInfo];
page.loadFinished = NO;
}
选择器方法接收NSTimer作为其参数,而不是userInfo。然后,使用NSTimer检索先前设置为userInfo的对象。
(在原始的-setLoadingNotFinished中,页面不是WebViewController,而是NSTimer。而且setLoadFinished被发送到NSTimer,后者无法识别它。)
请注意,错误消息告诉您选择器方法已发送到_NSCFTimer类的对象。这为您提供了有关错误性质的线索。
关于iphone - iPhone-对象在NSTimed调用上不再支持已知的选择器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5774253/