1

I am working on an application that supports iOS 7 and 8. The application works fine on iOS 7 but when I run it on iOS 8, it freezes when I press one of the UITextFields.

I have read other answers that talk about not having the UITextField as it's own delegate. Here is one of those answers: Application freezes after editing custom UITextField

However, to test this out, I have dragged a new UITextField into the application and not set up the delegate. I have also dragged out a UIButton.

When I click the UIButton everything is fine. However, when I click the UITextField (the one with no delegate set) the application still freezes.

pls
  • 1,522
  • 2
  • 21
  • 41
  • 1
    Can you post the stack trace when the app is frozen? Tap the "pause" button on the lower part of Xcode and you will see the stack on the left pane. – Léo Natan May 12 '15 at 09:33
  • Like what leo said, but use an exception breakpoint (because EXC_BAD_ACCESS is probably caused by a recursive call to freeze the app) – Schemetrical May 12 '15 at 10:02
  • 1
    I don't think EXC_BAD_ACCESS is thrown in cases of stack overflow. Also, @pls mentioned the app is frozen, not crashing. – Léo Natan May 12 '15 at 10:17
  • 1
    Cheers for the comment Leo. I have paused the app and I have found the problem. I will leave an answer to the question. Thanks Schemetrical for the additional information. – pls May 12 '15 at 10:24
  • Yes in this case Leo is correct. The app was not crashing. – pls May 12 '15 at 10:30

2 Answers2

2

Firstly thanks again to Leo for his very helpful comment. It seems that whenever you press a UITextField viewWillLayoutSubviews gets called.

Here is the code from the application:

- (void)viewWillLayoutSubviews
{
    [super viewWillLayoutSubviews];
    self.view.superview.bounds = CGRectMake(0.0, 0.0, 616.0, 703.0);
}

It seems that in iOS 8 you can't call self.view.superview.bounds because it causes an infinite loop. See the following answer for details:

https://stackoverflow.com/a/25934574/2126233

Community
  • 1
  • 1
pls
  • 1,522
  • 2
  • 21
  • 41
1

In my case, I was overriding the draw method and altering the layer. Infinite loop occurred in a UITextField, when the user reached the end of the canvas and he wanted to type more.

Paul Razvan Berg
  • 16,949
  • 9
  • 76
  • 114
  • In my case (iOS 15), I had a fixed width set for the UITextField, and a font being set programmatically inside viewWillLayoutSubviews. This also caused the app to freeze when the text inside the field exceeded the field's width. – Quack E. Duck Apr 04 '22 at 22:53
  • Resolved (in my case) by implementing a custom subclass of UITextView which scrolls text out of view before it reaches the edge of the field. This let me keep the width constraints and the fixed font size set in viewWillLayoutSubviews, which were both important to the layout of the app – Quack E. Duck Apr 04 '22 at 22:55