草庐IT

objective-c - AppDelegate 提示实现不完整,并在充满指针的调试 View 中崩溃

coder 2024-01-26 原文

我的代码有问题,在我开始添加 myImageView 代码之前它工作正常,但是 appDelegate 不完整实现警告已经存在很长时间了。

我的 appDelegate.h

//
//  AppDelegate.h
//  drawern
//
//  Created by Marin Jelica on 2012-11-21.
//  Copyright (c) 2012 Marin Jelica. All rights reserved.
//


#import <UIKit/UIKit.h>

@class ViewController;

@interface AppDelegate : UIResponder <UIApplicationDelegate/*, UIScrollViewDelegate*/>
/*{
 //   IBOutlet UIScrollView *myScrollView;
 //   UIImageView *myImageView;
}*/

@property (strong, nonatomic) UIWindow *window;

@property (strong, nonatomic) ViewController *viewController;
/*
@property (strong, nonatomic) UIScrollView *myScrollView;

@property (strong, nonatomic) UIImageView *myImageView;
*/
-(void)setRed;
-(void)setGreen;
-(void)setBlue;
@end

我的 appDelegate.M

//
//  AppDelegate.m
//  drawern
//
//  Created by Marin Jelica on 2012-11-21.
//  Copyright (c) 2012 Marin Jelica. All rights reserved.
//

#import "AppDelegate.h"

#import "ViewController.h"


@implementation AppDelegate

//@synthesize myImageView;
//@synthesize myScrollView;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
   /* UIImage *myImage = [UIImage imageNamed:@"de_dust2.png"];
    myImageView = [[UIImageView alloc] initWithImage:myImage];

    myScrollView.contentSize = CGSizeMake(myImageView.frame.size.width, myImageView.frame.size.height);
    myScrollView.maximumZoomScale = 4.0;
    myScrollView.minimumZoomScale = 0.75;
    myScrollView.clipsToBounds = YES;
    myScrollView.delegate = self;
    // [myScrollView addSubview:myImageView];*/

    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
    self.window.rootViewController = self.viewController;
    [self.window makeKeyAndVisible];
    [self.viewController setRed:1];
    [self.viewController setGreen:0];
    [self.viewController setBlue:0];
    [self.viewController setAlpha:1];
    [self.viewController checkRotation];
    return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application
{
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
    // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application
{
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end

我的viewController.h

//
//  ViewController.h
//  drawern
//
//  Created by Marin Jelica on 2012-11-21.
//  Copyright (c) 2012 Marin Jelica. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController {

    CGPoint lastPoint;
    CGPoint moveBackTo;
    CGPoint currentPoint;
    CGPoint location;
    NSDate *lastClick;
    BOOL mouseSwiped;
    UIImageView *drawImage;
    UIImageView *frontImage;
}
- (IBAction)blueButton:(id)sender;
- (IBAction)greenButton:(id)sender;
- (void)checkRotation;

@property int red;
@property int green;
@property int blue;
@property int alpha;
@property int height;
@property int width;

@end

我的viewController.m

//
//  ViewController.m
//  drawern
//
//  Created by Marin Jelica on 2012-11-21.
//  Copyright (c) 2012 Marin Jelica. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

@synthesize red;
@synthesize green;
@synthesize blue;
@synthesize alpha;
@synthesize height;
@synthesize width;


- (void)viewDidLoad
{
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    drawImage.image = [defaults objectForKey:@"drawImageKey"];
    drawImage = [[UIImageView alloc] initWithImage:nil];
    drawImage.frame = self.view.frame;
    [self.view addSubview:drawImage];

    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    width=3000;
    height=3000;
    // UIImage *image = [[UIImage alloc] init]


   /*
    UIImage *myImage = [UIImage imageNamed:@"de_dust2.png"];
    myImageView = [[UIImageView alloc] initWithImage:myImage];

    myScrollView.contentSize = CGSizeMake(myImageView.frame.size.width, myImageView.frame.size.height);
    myScrollView.maximumZoomScale = 4.0;
    myScrollView.minimumZoomScale = 0.75;
    myScrollView.clipsToBounds = YES;
    myScrollView.delegate = self;
    // [myScrollView addSubview:myImageView];*/
}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    UITouch *touch = [[event allTouches] anyObject];

    if ([touch tapCount] == 2) {
        drawImage.image = nil;
    }


    location = [touch locationInView:touch.view];
    lastClick = [NSDate date];

    lastPoint = [touch locationInView:self.view];
    lastPoint.y -= 0;

    [super touchesBegan: touches withEvent: event];
}


- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
    mouseSwiped = YES;

    UITouch *touch = [touches anyObject];
    currentPoint = [touch locationInView:self.view];

    UIGraphicsBeginImageContext(CGSizeMake(width , height));
    [drawImage.image drawInRect:CGRectMake(0, 0, width, height)];
    CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
    CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 2.0);
    CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), red, green, blue, alpha);
    CGContextBeginPath(UIGraphicsGetCurrentContext());
    CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
    CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), currentPoint.x, currentPoint.y);
    CGContextStrokePath(UIGraphicsGetCurrentContext());


    [drawImage setFrame:CGRectMake(0, 0, width, height)];
    drawImage.image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    lastPoint = currentPoint;

    [self.view addSubview:drawImage];
}


- (IBAction)blueButton:(id)sender {
    blue=1;
    red=0;
    green=0;
}


- (IBAction)greenButton:(id)sender {
 green=1;
    blue=0;
    red=0;   
}

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
    [self checkRotation];
}


-(void)checkRotation{

    NSLog(@"Width:%i", width);
    NSLog(@"Height:%i", height);


    UIInterfaceOrientation orientation = self.interfaceOrientation;
    if (orientation==UIInterfaceOrientationLandscapeRight || orientation == UIInterfaceOrientationLandscapeLeft) {
     //   width = 3000;
     //   height = 3000;


        [drawImage setFrame:CGRectMake(0, 0, width, height)];
     //   drawImage.image = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
        lastPoint = currentPoint;

        [self.view addSubview:drawImage];
    }

    if (UIInterfaceOrientationIsPortrait(orientation)) {
     //   width = 3000;
     //   height = 3000;


        [drawImage setFrame:CGRectMake(0, 0, width, height)];
   //     drawImage.image = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
        lastPoint = currentPoint;

        [self.view addSubview:drawImage];
    }
}

@end

这是启动时崩溃时发生的情况的图像

最佳答案

由于您在 appdelegate.h 文件中添加了以下方法定义,因此期望它在 appdelegate.m 中实现,但编译器无法在那里找到它.这就是它显示该警告的原因。

-(void)setRed;
-(void)setGreen;
-(void)setBlue;

您可以删除这些行或在 .m 文件中实现相同的行。

- (void)setRed {
  //set red color here
}

- (void)setGreen {
  //set green color here
}

- (void)setBlue {
  //set blue color here
}

你需要改变这一行,

drawImage.image = [defaults objectForKey:@"drawImageKey"];
drawImage = [[UIImageView alloc] initWithImage:nil];

用作,

UIImage *image = //get the image from defaults.. Is [defaults objectForKey:@"drawImageKey"] returning NSData of UIImage object? If not create UIImage object using the return name from this key
//if it returns a string, you can do the following
UIImage *image = [UIImage imageNamed:[defaults objectForKey:@"drawImageKey"]];

drawImage = [[UIImageView alloc] initWithImage:image];    

始终确保 [super viewDidLoad]; 是方法中的第一个调用。

- (void)viewDidLoad 
  {
     [super viewDidLoad];

关于objective-c - AppDelegate 提示实现不完整,并在充满指针的调试 View 中崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13519817/

有关objective-c - AppDelegate 提示实现不完整,并在充满指针的调试 View 中崩溃的更多相关文章

  1. ruby - 为什么我可以在 Ruby 中使用 Object#send 访问私有(private)/ protected 方法? - 2

    类classAprivatedeffooputs:fooendpublicdefbarputs:barendprivatedefzimputs:zimendprotecteddefdibputs:dibendendA的实例a=A.new测试a.foorescueputs:faila.barrescueputs:faila.zimrescueputs:faila.dibrescueputs:faila.gazrescueputs:fail测试输出failbarfailfailfail.发送测试[:foo,:bar,:zim,:dib,:gaz].each{|m|a.send(m)resc

  2. ruby-on-rails - Rails - 一个 View 中的多个模型 - 2

    我需要从一个View访问多个模型。以前,我的links_controller仅用于提供以不同方式排序的链接资源。现在我想包括一个部分(我假设)显示按分数排序的顶级用户(@users=User.all.sort_by(&:score))我知道我可以将此代码插入每个链接操作并从View访问它,但这似乎不是“ruby方式”,我将需要在不久的将来访问更多模型。这可能会变得很脏,是否有针对这种情况的任何技术?注意事项:我认为我的应用程序正朝着单一格式和动态页面内容的方向发展,本质上是一个典型的网络应用程序。我知道before_filter但考虑到我希望应用程序进入的方向,这似乎很麻烦。最终从任何

  3. ruby-on-rails - 渲染另一个 Controller 的 View - 2

    我想要做的是有2个不同的Controller,client和test_client。客户端Controller已经构建,我想创建一个test_clientController,我可以使用它来玩弄客户端的UI并根据需要进行调整。我主要是想绕过我在客户端中内置的验证及其对加载数据的管理Controller的依赖。所以我希望test_clientController加载示例数据集,然后呈现客户端Controller的索引View,以便我可以调整客户端UI。就是这样。我在test_clients索引方法中试过这个:classTestClientdefindexrender:template=>

  4. ruby - 检查 "command"的输出应该包含 NilClass 的意外崩溃 - 2

    为了将Cucumber用于命令行脚本,我按照提供的说明安装了arubagem。它在我的Gemfile中,我可以验证是否安装了正确的版本并且我已经包含了require'aruba/cucumber'在'features/env.rb'中为了确保它能正常工作,我写了以下场景:@announceScenario:Testingcucumber/arubaGivenablankslateThentheoutputfrom"ls-la"shouldcontain"drw"假设事情应该失败。它确实失败了,但失败的原因是错误的:@announceScenario:Testingcucumber/ar

  5. ruby - 主要 :Object when running build from sublime 的未定义方法 `require_relative' - 2

    我已经从我的命令行中获得了一切,所以我可以运行rubymyfile并且它可以正常工作。但是当我尝试从sublime中运行它时,我得到了undefinedmethod`require_relative'formain:Object有人知道我的sublime设置中缺少什么吗?我正在使用OSX并安装了rvm。 最佳答案 或者,您可以只使用“require”,它应该可以正常工作。我认为“require_relative”仅适用于ruby​​1.9+ 关于ruby-主要:Objectwhenrun

  6. Ruby Readline 在向上箭头上使控制台崩溃 - 2

    当我在Rails控制台中按向上或向左箭头时,出现此错误:irb(main):001:0>/Users/me/.rvm/gems/ruby-2.0.0-p247/gems/rb-readline-0.4.2/lib/rbreadline.rb:4269:in`blockin_rl_dispatch_subseq':invalidbytesequenceinUTF-8(ArgumentError)我使用rvm来管理我的ruby​​安装。我正在使用=>ruby-2.0.0-p247[x86_64]我使用bundle来管理我的gem,并且我有rb-readline(0.4.2)(人们推荐的最少

  7. ruby-on-rails - 如果 Object::try 被发送到一个 nil 对象,为什么它会起作用? - 2

    如果您尝试在Ruby中的nil对象上调用方法,则会出现NoMethodError异常并显示消息:"undefinedmethod‘...’fornil:NilClass"然而,有一个tryRails中的方法,如果它被发送到一个nil对象,它只返回nil:require'rubygems'require'active_support/all'nil.try(:nonexisting_method)#noNoMethodErrorexceptionanymore那么try如何在内部工作以防止该异常? 最佳答案 像Ruby中的所有其他对象

  8. ruby-on-rails - 如何在我的 Rails 应用程序 View 中打印 ruby​​ 变量的内容? - 2

    我是一个Rails初学者,但我想从我的RailsView(html.haml文件)中查看Ruby变量的内容。我试图在ruby​​中打印出变量(认为它会在终端中出现),但没有得到任何结果。有什么建议吗?我知道Rails调试器,但更喜欢使用inspect来打印我的变量。 最佳答案 您可以在View中使用puts方法将信息输出到服务器控制台。您应该能够在View中的任何位置使用Haml执行以下操作:-puts@my_variable.inspect 关于ruby-on-rails-如何在我的R

  9. ruby - 如何根据特征实现 FactoryGirl 的条件行为 - 2

    我有一个用户工厂。我希望默认情况下确认用户。但是鉴于unconfirmed特征,我不希望它们被确认。虽然我有一个基于实现细节而不是抽象的工作实现,但我想知道如何正确地做到这一点。factory:userdoafter(:create)do|user,evaluator|#unwantedimplementationdetailshereunlessFactoryGirl.factories[:user].defined_traits.map(&:name).include?(:unconfirmed)user.confirm!endendtrait:unconfirmeddoenden

  10. ruby-on-rails - 如何在 Rails View 上显示错误消息? - 2

    我是rails的新手,想在form字段上应用验证。myviewsnew.html.erb.....模拟.rbclassSimulation{:in=>1..25,:message=>'Therowmustbebetween1and25'}end模拟Controller.rbclassSimulationsController我想检查模型类中row字段的整数范围,如果不在范围内则返回错误信息。我可以检查上面代码的范围,但无法返回错误消息提前致谢 最佳答案 关键是您使用的是模型表单,一种显示ActiveRecord模型实例属性的表单。c

随机推荐