others-how to solve errors when using custom tableviewcell in iOS apps

1. Purpose

In this post, I would demo how to solve a series of problems when using custom tableviewcell in iOS native app development.

2. Environment

  • Mac OS 10.15
  • Swift 5
  • Xcode 12

3. The problems and the solutions

3.1 Problem #1

When we create a custom tableviewcell with XIB file, we get this error:

Thread 1: "Could not load NIB in bundle: 'NSBundle </private/var/containers/Bundle/Application/5CE177AA-A76A-4FDE-968A-2EED5EF138EB/LanrenReceiver1.app> (loaded)' with name 'MessageDetailCell'"

The solution: We should check if we have checked the target for the custom cell class MessageDetailCell and its xib file. After checking the target, the problem solved.

3.2 Problem #2

When we add views to our custom tableviewcell , we get this error:

Thread 1: "invalid nib registered for identifier (reuseIdentifier3) - nib must contain exactly one top level object which must be a UITableViewCell instance"

The solution: we should check if the view is put at the wrong level of the xib view tree. Just check the view hierarchy tree, check if the view is put at the wrong place. After move the view to the right level of the tree, the problem solved.

3.3 Problem #3

When we want to show multiline textview in the custom cell , only one line was shown, the other text is hidden!

The solution: We should check the textview, make sure that the lines property is set to 0, and aslo you should add constraint to the right side of the textview, or else the texts would not show multilines, at last, you should check its parent view’s content mode, set it to scale to fill.

Now it works!

4. Summary

In this post, I demonstrated how to solve a series of problems when using custom table view cell in iOS development.

-->