开发者

crashing application when entering UITextField

I use this to hide keyboard when i click done button or outside of text field:

in view did load:

PidField.returnKeyType = UIReturnKeyDone;
PidField.delegate = self;
HesloField.returnKeyType = UIReturnKeyDone;
HesloField.delegate = self;

then in program:

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

    if (theTextField == PidField) {
        [PidField resignFirstResponder];
    }
    if (theTextField == HesloField) {
        [HesloField resignFirstResponder];
    }

    return YES;

}

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

    [PidField resignFirstResponder];
    [HesloField resignFirstResponder];

}

It is good and tested code i used it many times, but now when i enter the textfield it makes my app crash. i do not understand it why or where i have to find the error

thanks

//
//  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 superv开发者_运维百科iew.
    [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;
}

remove this and try...

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

    [PidField resignFirstResponder];
    [HesloField resignFirstResponder];

}

and in .h file write delegate UITextViewDelegate

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜