Signo Signo - 3 months ago 27
iOS Question

UITextField RightView crash app when using 2 or more

I don't know if this is a bug or what but I can't understand why it happens.
I have 2

UITextField
that once clicked show the users an
UIPickerView
, everything was working fine until I tried to add a custom arrow image in order to let the user know about the dropdown. this is the code I've used in order to create the rightView:

UIImageView *arrowDown = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"p-dropdown"]];
arrowDown.frame = CGRectMake(0, 0, 26, 22);
_province.rightViewMode = UITextFieldViewModeAlways;
_province.rightView = arrowDown;
_address.rightViewMode = UITextFieldViewModeAlways;
_address.rightView = arrowDown;


As soon as the last line ends the app freezes and it starts using like 20MB/s of RAM without stopping, I tried to comment all the code above and the problem doesn't occur, the funny thing is that if I comment just one of the two rightView ,so something like this:

UIImageView *arrowDown = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"p-dropdown"]];
arrowDown.frame = CGRectMake(0, 0, 26, 22);
_province.rightViewMode = UITextFieldViewModeAlways;
_province.rightView = arrowDown;


I can correctly see the rightView and the app doesn't freeze. Can someone help me to understand what is causing this weird issue?

Answer

One instance of UIView can't be utilized as right view of multiple UITextFields. You have to make two instances of your UIImageView to make your app work as expected. As you yourself found out, that one view cant be displayed on a screen multiple times simultaneously.

Comments