未声明的标识符viewForZoomingInScrollView

时间:2013-03-12 04:51:06

标签: undeclared-identifier

这是我的协议

#import <UIKit/UIKit.h>
#import "HypnosisterView.h"

@interface HypnosisterAppDelegate : UIResponder <UIApplicationDelegate,UIScrollViewDelegate>
{
HypnosisterView *view;
}

@property (strong, nonatomic) UIWindow *window;

@end

这是委托

的实现
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.

CGRect screenRect = [[self window]bounds];

UIScrollView *scrollView = [[UIScrollView alloc]initWithFrame:screenRect];

[scrollView setMaximumZoomScale:1.0];
[scrollView setMaximumZoomScale:5.0];

[scrollView setDelegate:self];

[[self window]addSubview:scrollView];

CGRect bigRect = screenRect;
view = [[HypnosisterView alloc]initWithFrame:screenRect];
[scrollView addSubview:view];
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
    return view;
}

[scrollView setContentSize:bigRect.size];


BOOL success = [view becomeFirstResponder];
if (success) {
    NSLog(@"HypnosisView became the first responder");
}else{
    NSLog(@"Couldn't become first responder");
}


self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}

即使确认协议给出错误未声明的标识符viewForZoomingInScrollView。 我从Apple文档中复制了这个方法,并通过跳转到该委托的定义来交叉验证。 它显示了未声明的原因,也就是为什么不出现在自我暗示中。 请帮帮我。 感谢。

1 个答案:

答案 0 :(得分:1)

当你意识到错误时,你可能会踢自己。我实现了你的代码并得到了同样的错误。尽管你覆盖了一个方法,因此不需要在你的.h文件中声明它......我还是决定这样做。不过,未申报。

就在这时,我意识到你已经为你的'viewForZoomingInScrollView'编写了方法 - (BOOL)应用程序:applicationDidFinishLaunchingWithOptions方法。所以我将它从上面移除并将问题解决了。

tldr:从

中删除viewForZoomingInScrollView方法

- (BOOL)应用程序:applicationDidFinishLaunchingWithOptions方法。