【问题标题】:Undeclared identifier viewForZoomingInScrollView未声明的标识符 viewForZoomingInScrollView
【发布时间】:2013-03-12 04:51:05
【问题描述】:

这是我的协议

#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. 我已经从苹果文档中复制了这个方法,并通过跳转到该委托的定义进行了交叉验证。 它显示未声明的这就是为什么也没有出现在自动建议中。 请帮帮我。 谢谢。

【问题讨论】:

    标签: undeclared-identifier


    【解决方案1】:

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

    此时我才意识到您已经在您的 -(BOOL)应用程序:applicationDidFinishLaunchingWithOptions 方法。所以我把它从那里取下来,放在上面,问题就解决了。

    tldr:从

    中移除 viewForZoomingInScrollView 方法

    -(BOOL)application:applicationDidFinishLaunchingWithOptions 方法。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-30
      • 1970-01-01
      • 2021-06-07
      • 2016-04-09
      • 2020-12-09
      • 2016-04-22
      相关资源
      最近更新 更多