1

这是我的协议

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

4

1 回答 1

1

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

正是在这一点上,我意识到您已经在您的 -(BOOL)application:applicationDidFinishLaunchingWithOptions 方法中编写了“viewForZoomingInScrollView”的方法。所以我把它从那里取下来,放在上面,问题就解决了。

tldr:删除 viewForZoomingInScrollView 方法

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

于 2013-11-25T12:35:20.670 回答