Thomas K
Thomas K

Reputation: 6196

App freezes when begin editing UITextField

I've got two UITextFields firstname and email. I've got those as retained properties in my .h file and I synthesize them in my .m file. Editing the firstname field works fine. However as soon as I tap the email textfield to edit it, the app just freezes. It doesn't crash so there's nothing useful in the debugger.

This is what I have in viewDidLoad.

- (void)viewDidLoad
{
    [super viewDidLoad];


    firstname.delegate = self;
    email.delegate = self;
    email.adjustsFontSizeToFitWidth = YES;    

    UIView *paddingView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 20)];
    email.leftView = paddingView;
    email.leftViewMode = UITextFieldViewModeAlways;
    email.rightView = paddingView;
    email.rightViewMode = UITextFieldViewModeAlways;

    firstname.leftView = paddingView;
    firstname.leftViewMode = UITextFieldViewModeAlways;
    firstname.rightView = paddingView;
    firstname.rightViewMode = UITextFieldViewModeAlways;

    [paddingView release];
  }

Anyone got a clue?

Thanks!

Upvotes: 2

Views: 1688

Answers (2)

Thomas K
Thomas K

Reputation: 6196

Ok fixed it.

A single UIView (or UIImageView) cannot be displayed on screen twice at the same time. I fixed this by creating separate padding views for the UITextFields.

Upvotes: 18

Praveen-K
Praveen-K

Reputation: 3401

What is the leftView here? and

why you are releasing the paddingView ???

Try

[paddingView addSubView:firstname];
[paddingView addSubView:email];

Upvotes: -1

Related Questions