TableView.dequeueReusableCellWithIdentifier () makes the application freeze

ORIGINAL MAIL

We recently converted our app to Swift 2.0 and iOS9. One strange problem that I see is that calling tableView.dequeueReusableCellWithIdentifier () causes the application to hang in the simulator.


Code
func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? { //hangs on the line below let headersection: HeaderSectionCell = tableView.dequeueReusableCellWithIdentifier("SectionHeader") as! HeaderSectionCell ... return headersection } 

Header cell

 class HeaderSectionCell: UITableViewCell { @IBOutlet var labelOne: UITextView! @IBOutlet var labelTwo: UITextView! @IBOutlet var textView: UITextView! } 

CPU utilization for 100% binding

Pegging CPU


After pausing in Xcode, it shows me that it hangs over this Swift function.

Pausing at the show shows us here.


Here are some of the routines in which iOS loops under the covers.

enter image description here

enter image description here

Finally, our Swift call for dequeueReusableCellWithIdentifier () enter image description here

This particular hanging instance is from the tableView(tableView: UITableView, viewForHeaderInSection section: Int) function tableView(tableView: UITableView, viewForHeaderInSection section: Int) , but we are also inside the call to tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) with the same problem.

I tried playing with the properties of the cells in the storyboard editor, but nothing is different from other views that work fine.

EDIT

There seems to be an endless loop between Foundation and libobjc.A.dylib, under this call to dequeReusableCellWithIdentifier (). I ended up importing the Foundation in front of any other structures and abstracting the abusive UITableViewCell in its own class (reused). The original call now works, but there is another one that is still looping under the Swift covers, which I work to understand.

Enabling a pause in an infinite loop puts me in the same place on the assembly stack:

Top stack trace after pause:

 libobjc.A.dylib`objc_msgSend: 0x107f6a800 <+0>: testq %rdi, %rdi 0x107f6a803 <+3>: jle 0x107f6a850 ; <+80> 0x107f6a805 <+5>: movq (%rdi), %r11 0x107f6a808 <+8>: movq %rsi, %r10 0x107f6a80b <+11>: andl 0x18(%r11), %r10d 0x107f6a80f <+15>: shlq $0x4, %r10 0x107f6a813 <+19>: addq 0x10(%r11), %r10 0x107f6a817 <+23>: cmpq (%r10), %rsi 0x107f6a81a <+26>: jne 0x107f6a820 ; <+32> -> 0x107f6a81c <+28>: jmpq *0x8(%r10) 

Top stack trace after another pause:

 Foundation`-[NSLocalizableString length]: 0x1071c5cbc <+0>: pushq %rbp 0x1071c5cbd <+1>: movq %rsp, %rbp -> 0x1071c5cc0 <+4>: movq 0x80461(%rip), %rax ; NSLocalizableString._developmentLanguageString 0x1071c5cc7 <+11>: movq (%rdi,%rax), %rdi 0x1071c5ccb <+15>: movq 0x7436e(%rip), %rsi ; "length" 0x1071c5cd2 <+22>: popq %rbp 0x1071c5cd3 <+23>: jmpq *0x8ea77(%rip) ; (void *)0x0000000107f6a800: objc_msgSend 

It just loops between these two downstream procedures, consuming 100% of the CPU simulator.

+5
source share
4 answers

This was a string localization issue. The UITableViewCell contained a UITextField with a non-empty value for the Text property, in which English was not set in the UITextView localization properties.

Checking English fixed the problem.

Such a pain! Go figure, why not loop endlessly, and not throw an understandable mistake?

+13
source

My solution was similar to styler1972's.

In my case, I updated the Swift / Objective-C combination of the project from Swift 1.2 to Swift 2.0. The app worked successfully on iOS 9 before upgrading to Swift 2.0. After upgrading to Swift 2.0, the application will enter an endless loop when switching from the Table View cell application to the view controller. Running the application in the simulator and then pausing it when it got into an infinite loop left me at [NSLocalizableString length] (which led me to this post).

My solution was to do the following.

  • Delete the Main.storyboard file from the en.lproj directory.
  • Delete the en.lproj directory, including the InfoPlist.strings file.
  • Place Main.storyboard in the root directory of the project.
  • Refresh the project to reflect the above changes.
  • In the project settings in the "Information / Localization" section, delete all settings.
  • Clean the build directory (for a good estimate).
  • Clean the assembly (for a good grade).
  • Create and run.

An infinite loop is no longer found.

+5
source

Be sure to back up the project files in order to restore the localization files later.

  • In the project settings, localization, delete all localizations except the project development language (for me it was English).
  • Clean and run. At this point, you will no longer see the error.
  • Add the locales you deleted above and restore the localization from your backup.
+3
source

use dequeueReusableHeaderFooterViewWithIdentifier instead of dequeueReusableCellWithIdentifier

You are trying to load a cell in viewForHeaderInSection, which is also incorrect.

Edited by:

 class HeaderSectionView: UITableViewHeaderFooterView { @IBOutlet var labelOne: UITextView! @IBOutlet var labelTwo: UITextView! @IBOutlet var textView: UITextView! } 

and

 func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? { //hangs on the line below let headersection: HeaderSectionView = tableView.dequeueReusableHeaderFooterViewWithIdentifier("SectionHeader") as! HeaderSectionView ... return headersection } 

Remember to register HeaderSectionView as

 tableView.registerNib(UINib(nibName: "HeaderSectionView", bundle:nil), forHeaderFooterViewReuseIdentifier: "SectionHeader") 
0
source

All Articles