0

将局部变量更改为实例变量后,我的代码遇到了一些问题。具体来说,在从以下位置更改一行代码后,我的 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

催眠视图.h

#import <Foundation/Foundation.h>

@interface HypnosisView : UIView {

}

@property(nonatomic,strong)UIColor *circleColor;
@end
4

1 回答 1

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稍后添加为子视图。

于 2012-04-28T20:19:04.100 回答