Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I am getting an error - nib must contain exactly one top level object which must be a UITableViewCell instance'"

Tags:

I am using a custom cell in my tableView but when I run i get the error which I have mentioned in my question.

 self.districtTableView.register(UINib(nibName: "PlaceCollectionViewCell", bundle: nil), forCellReuseIdentifier: "placeCell")   func textFieldShouldBeginEditing(_ textField: UITextField) -> Bool {     return false }  func textFieldDidEndEditing(_ textField: UITextField) {     // TODO: Your app can do something when textField finishes editing      print("The textField ended editing. Do something based on app requirements.") }  func numberOfSections(in tableView: UITableView) -> Int {      return 1 }  func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {     return districts.count }  func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {      let cell = tableView.dequeueReusableCell(withIdentifier: "placeCell") as! PlaceTableViewCell     // Set text from the data model     cell.distLabel.text = districts[indexPath.row]     cell.textLabel?.font = distTextField.font     return cell 

How can I get rid of this error. I have used different methods for registering a cell in table view. But it does not works. please help

like image 425
Rakesh Mohan Avatar asked Dec 16 '16 09:12

Rakesh Mohan


2 Answers

I have added Tap gestures from Interface builder (XIB).

Remove that will solve this issue.

You have to add gesture in xib by programatically way

like image 128
Prashant Tukadiya Avatar answered Oct 06 '22 03:10

Prashant Tukadiya


In my case it was a view which was added outside the cell. It shouldn't have been there

enter image description here

like image 31
milczi Avatar answered Oct 06 '22 03:10

milczi