3

I have a button in my storyboard that presents a view controller with a modal segue. Every time this button is pressed, the app freezes (There is no crash and no error message). prepareForSegue is called and all the view controllers that should be there are there in code in prepareForSegue, but they don't appear onscreen. I can modal segue from the same button to another view controller just fine. Any ideas on why this is happening or how to fix it?

Things I have tried:

  1. Deleting button or using a different button
  2. Recreating the segue in IB
Kevin
  • 16,696
  • 7
  • 51
  • 68

2 Answers2

1

Finally got Xcode to give me an error message... turns out I had done

if (self == [super init]) {
}

when I should have done

if (self = [super init]) {
}

which caused all sorts of memory problems.

Kevin
  • 16,696
  • 7
  • 51
  • 68
  • for that I wanted to see your code :) some time is little mistake that break all the app – Mirko Catalano Oct 08 '13 at 10:24
  • This is a bad practice, however, because it's all too easy (as you found out the hard way) to use `==` because you see that it's in an `if`. Much better is to break it out explicity, like `self = [super init]; if (self) { ... }`. – NRitH Oct 15 '15 at 14:23
  • Wouldn't changing the "==" to "=" make the if statement always return true? – Zack Oct 15 '15 at 14:36
  • It will return true only when the super initialization is successful. This is basically how Obj-C handles failable initializers. The if statement is a guard against allocating memory for instance variables when the super call was nil. – Kevin Oct 15 '15 at 19:10
0

I had a similar issue in iOS 9 that was fixed by not setting any text in UITextViews, in the storyboard, that were in the destination view controller... bizarre but it fixed it!

iOS 9 Segue Causes App To Freeze (no crash or error thrown)

Community
  • 1
  • 1
CMash
  • 1,987
  • 22
  • 35