将局部变量更改为实例变量后,我的代码出现问题。具体来说,在更改了一行代码后,我的HypnosisterAppDelegate.m文件中的代码出现问题:
HypnosisView *view = [[HypnosisView alloc]initWithFrame:screenRect];
到
view = [[HypnosisView alloc]initWithFrame:screenRect];
我在HypnosisterAppDelegate.m中注释掉了错误消息你能告诉我什么是错的吗?提前谢谢。
HypnosisterAppDelegate.m
#import "HypnosisterAppDelegate.h"
#import "HypnosisView.h"
@implementation HypnosisterAppDelegate
@synthesize window = _window;
- (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];
// Create the UIScrollView to have the size of a window, matching its size
view = [[HypnosisView alloc]initWithFrame:screenRect];
[scrollView setMinimumZoomScale:1.0]; // Unknown receiver "scrollView"; should it be "UIScrollView"?
[scrollView setMaximumZoomScale:5.0]; // Unknown receiver "scrollView"; should it be "UIScrollView"?
//You will get a warning here, ignore it for now
[scrollView setDelegate:self]; // Unknown receiver "scrollView"; should it be "UIScrollView"?
[[self window] addSubview:scrollView]; // Unknown receiver "scrollView"; should it be "UIScrollView"?
//Create the HypnosisView with a frame that is twice the size of the screen
CGRect bigRect = screenRect;
HypnosisView *view = [[HypnosisView alloc]initWithFrame:screenRect];
// Add the HypnosisView as a subview of the scrollView instead of the window
[scrollView addSubview:view]; // Unknown receiver "scrollView"; should it be "UIScrollView"?
// Tell the scrollView how big its virtual world is
[scrollView
setContentSize:bigRect.size]; // Unknown receiver "scrollView"; should it be "UIScrollView"?
BOOL success = [view becomeFirstResponder];
if (success) {
NSLog(@"HypnosisView became the first responder");
} else {
NSLog(@"Could not become the first responder");
}
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
-(UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
return view;
}
@end
HypnosisView.h
#import <Foundation/Foundation.h>
@interface HypnosisView : UIView {
}
@property(nonatomic,strong)UIColor *circleColor;
@end
答案 0 :(得分:0)
您在任何地方都没有名为scrollView
的变量。我猜(特别是来自评论// Create the UIScrollView to have the size of a window, matching its size
,并且我自己也经历了这本书)你打算创建一个UIScrollView
:
// not: view = [[HypnosisView alloc]initWithFrame:screenRect];
// but:
UIScrollView * scrollView = [[UIScrollView alloc] initWithFrame:screenRect];
然后将您的HypnosisView
稍后添加为子视图。