Objective c 进入UITextField时应用程序崩溃

Objective c 进入UITextField时应用程序崩溃,objective-c,cocoa-touch,uitextfield,Objective C,Cocoa Touch,Uitextfield,单击“完成”按钮或文本字段外部时,我使用此选项隐藏键盘: 考虑到以下情况: 然后在程序中: 这是很好的测试代码,我用过很多次,但现在当我进入文本字段时,我的应用程序崩溃了。我不明白为什么或者在哪里我必须找到错误 谢谢 // // InfoViewController.m // PhotoScroller // // Created by Csaba on 3/29/11. // Copyright 2011 __MyCompanyName__. All rights reserved.

单击“完成”按钮或文本字段外部时,我使用此选项隐藏键盘:

考虑到以下情况:

然后在程序中:

这是很好的测试代码,我用过很多次,但现在当我进入文本字段时,我的应用程序崩溃了。我不明白为什么或者在哪里我必须找到错误

谢谢

//
//  InfoViewController.m
//  PhotoScroller
//
//  Created by Csaba on 3/29/11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "InfoViewController.h"


@implementation InfoViewController
@synthesize PidField8, HesloField8;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)dealloc
{
    [super dealloc];
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.view.backgroundColor = [UIColor colorWithRed:205/255.0 green:234/255.0 blue:242/255.0 alpha:1]; 

    PidField8.returnKeyType = UIReturnKeyDone;
    PidField8.delegate = self;
    HesloField8.returnKeyType = UIReturnKeyDone;
    HesloField8.delegate = self;

}


-(BOOL)textFieldShouldReturn:(UITextField *)theTextField {

    if (theTextField == PidField8) {
        [PidField8 resignFirstResponder];
    }
    if (theTextField == HesloField8) {
        [HesloField8 resignFirstResponder];
    }

    return YES;

}


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

    [PidField8 resignFirstResponder];
    [HesloField8 resignFirstResponder];

}


- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end
删除此文件并尝试

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

    [PidField resignFirstResponder];
    [HesloField resignFirstResponder];

}
和在.h文件中写入委托
UITextViewDelegate

当我注释掉这一行时//HesloField.delegate=self;然后它不会掉落,但也不会隐藏键盘在调试模式下运行,并查看它在何处崩溃以及出现什么消息。此外,请应用命名约定,如以小写字母开头的IVAR。阅读和理解起来很痛苦。我先调试它,但我找不到它落在哪里。首先我调试,然后我问…:)尽管如此,这无助于做一件事。。复制一个粘贴你的整个类文件在这里。。。我想一下。。你又犯了一个错误1.我检查一下你的笔尖。。当你得到崩溃时?当我点击输入文本fieldUITextViewDelegate或UITextFieldDelegate时?
//
//  InfoViewController.m
//  PhotoScroller
//
//  Created by Csaba on 3/29/11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "InfoViewController.h"


@implementation InfoViewController
@synthesize PidField8, HesloField8;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)dealloc
{
    [super dealloc];
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.view.backgroundColor = [UIColor colorWithRed:205/255.0 green:234/255.0 blue:242/255.0 alpha:1]; 

    PidField8.returnKeyType = UIReturnKeyDone;
    PidField8.delegate = self;
    HesloField8.returnKeyType = UIReturnKeyDone;
    HesloField8.delegate = self;

}


-(BOOL)textFieldShouldReturn:(UITextField *)theTextField {

    if (theTextField == PidField8) {
        [PidField8 resignFirstResponder];
    }
    if (theTextField == HesloField8) {
        [HesloField8 resignFirstResponder];
    }

    return YES;

}


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

    [PidField8 resignFirstResponder];
    [HesloField8 resignFirstResponder];

}


- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end
- (BOOL)textFieldShouldReturn:(UITextField *)textField 
{

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

    [PidField resignFirstResponder];
    [HesloField resignFirstResponder];

}