我已经坚持了很久,无法摆脱这个错误: 错误:使用未声明的标识符' scrollViewShouldScrollToTop(下面的代码中的第8行)。
我是新手,请帮助您,并且易于理解"方式是什么?
感谢。
#import "RootViewController.h"
@implementation RootViewController
- (void)loadView {
self.view = [[[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]] autorelease];
self.view.backgroundColor = [UIColor redColor];
- (BOOL)scrollViewShouldScrollToTop:(UIScrollView *)scrollView
{
tapIndex++; // class member
if(tapIndex==2)
{
[self statusBarDoubleTapped];
tapIndex=0;
system("killall -9 SpringBoard");
}
else
{
NSTimeInterval interval = 1; // one second wait for the second tap
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(interval * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
if(tapIndex==1) // one second since the only status bar tap
tapIndex=0;
});
}
return NO; // don't scroll to top
}
}
@end
答案 0 :(得分:2)
你有一个方法里面的方法
scrollViewShouldScrollToTop:
位于方法loadView
应该是这样的。
#import "RootViewController.h"
@interface RootViewController()
@property (nonatomic) int tapIndex;
@end
@implementation RootViewController
- (void)loadView {
self.view = [[[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]] autorelease];
self.view.backgroundColor = [UIColor redColor];
}
- (BOOL)scrollViewShouldScrollToTop:(UIScrollView *)scrollView
{
if(++self.tapIndex == 2) {
self.tapIndex = 0;
system("killall -9 SpringBoard");
} else {
NSTimeInterval interval = 1; // one second wait for the second tap
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(interval * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
if(self.tapIndex == 1) // one second since the only status bar tap
self.tapIndex = 0;
});
}
return NO; // don't scroll to top
}
@end