Another SIGABRT error - ios

I am getting an error Thread1: signal SIGABRT in the line below, I already tried:
Product>Clean, Restart Computer
check all connections to the storyboard
check if some connection is lost
the Identifier is set to Cell in the attribute inspector
plus look into many posts in this forum.
After all this I deleted all connections with storyboard and connect again but still get the same error :(
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell2 = tableView.dequeueReusableCellWithIdentifier("cell2", forIndexPath: indexPath) as! DefinitionTableViewCell
In the console:
Assertion failure in -[UITableView dequeueReusableCellWithIdentifier:forIndexPath:], /SourceCache/UIKit/UIKit-3347.44/UITableView.m:6245
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'unable to dequeue a cell with identifier cell2 - must register a nib or a class for the identifier or connect a prototype cell in a storyboard'
Any help is more than welcome Tks :)

Well, as the exception message suggests, you "must register a nib or a class for the identifier". Try adding this line in viewDidLoad():
tableView.registerNib(UINib(nibName: "nameOfYourCustomNib", bundle: nil), forCellReuseIdentifier: "cell2")
Replace the nameOfYourCustomNib with your nib name, for example if you have a file MyCustomCell.xib then the name would be MyCustomCell.
If this fails, try registering a class instead of a nib (remember to delete the first line), by typing:
tableView.registerClass(DefinitionTableViewCell.self, forCellReuseIdentifier: "cell2")
And the most important thing, in cellForRowAtIndexPath, make sure you check if the cell is nil, and if so, create a new DefinitionTableViewCell.

Related

Unable to Dequeue Registered CollectionViewCells

Searched here and there but I couldn't find anything that I haven't already tried to fix my issue, so going to ask it again.
I am trying to use a collection view with custom cells.
The main collection view is in the Main View Controller.
I'm using a generic cell named GenericHomeCollectionViewCell, then customize another collection view that it has. This cell doesn't have any issue with registering and dequeuing. (It might sound weird but I already have an application with this usage and it works without any problem, so I wanted to use the same method again.)
The crash happens when I try to register and dequeue cells inside that generic cell.
I have 4 different custom cells for use which are registered in awakeFromNib().
GenericHomeCollectionViewCell.swift
override func awakeFromNib() {
super.awakeFromNib()
newsCollectionView.register(UINib(nibName: "HeadlineNewsCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: "HeadlineNewsCollectionViewCell")
newsCollectionView.register(UINib(nibName: "HomeAuthorCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: "HomeAuthorCollectionViewCell")
newsCollectionView.register(UINib(nibName: "NewsListCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: "NewsListCollectionViewCell")
newsCollectionView.register(UINib(nibName: "HomeDetailedNewCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: "HomeDetailedNewCollectionViewCell")
newsCollectionView.delegate = self
newsCollectionView.dataSource = self
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
if sectionType == .swipe {
let cell : HeadlineNewsCollectionViewCell = collectionView.dequeueReusableCell(withReuseIdentifier: "HeadlineNewsCollectionViewCell", for: indexPath) as! HeadlineNewsCollectionViewCell
cell.prepareCell(news: newsList[indexPath.row])
return cell
} else if sectionType == .homeAuthor {
let cell : HomeAuthorCollectionViewCell = collectionView.dequeueReusableCell(withReuseIdentifier: "HomeAuthorCollectionViewCell", for: indexPath) as! HomeAuthorCollectionViewCell
cell.prepareCell(news: newsList[indexPath.row])
return cell
} else {
let cell : HeadlineNewsCollectionViewCell = collectionView.dequeueReusableCell(withReuseIdentifier: "HeadlineNewsCollectionViewCell", for: indexPath) as! HeadlineNewsCollectionViewCell
cell.prepareCell(news: newsList[indexPath.row])
return cell
}
}
When I launch the application, I get crash with error:
*** Assertion failure in -[UICollectionView _dequeueReusableViewOfKind:withIdentifier:forIndexPath:viewCategory:], UICollectionView.m:6502
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'could not dequeue a view of kind: UICollectionElementKindCell with identifier HeadlineNewsCollectionViewCell - must register a nib or a class for the identifier or connect a prototype cell in a storyboard'
I tried to give a reuse identifier name from the storyboard editor's but there is no difference.

Storyboard UITableViewCell could not load nib in bundle with name... when loaded programmatically

I have a Viewcontroller scene (Storyboard) with a UITableView and inside a UITableViewCell called Foo. Foo loads fine when loaded from a storyboard, but I need to load it from another UITableView programmatically.
I'm registering the cell like this (at first I tried without UINib but IBOutlets were nil):
override func viewDidLoad() {
super.viewDidLoad()
tableView.register(UINib(nibName: "Foo", bundle: nil), forCellReuseIdentifier: "bar")
}
and then loading it like this:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "bar", for: indexPath) as! Foo
return cell
}
This doesn't work and returns the error:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle <[path]> (loaded)' with name 'Foo''
Things I made sure of:
The Foo UITableViewCell identifier in Attributes inspector is Foo
Has the correct Target Membership
You may want to create a separated nib file for your cell then register it to your table view like what you've done above.

Swift - could not dequeue a view of kind: UICollectionElementKindCell with identifier

I got this error message when trying to load UICollectionView.
2015-07-23 16:16:09.754 XXXXX[24780:465607] Terminating app due to
uncaught exception 'NSInternalInconsistencyException', reason: 'could
not dequeue a view of kind: UICollectionElementKindCell with
identifier CollectionViewCell - must register a nib or a class for the
identifier or connect a prototype cell in a storyboard'
First throw call stack:
My code
#IBOutlet var collectionView: UICollectionView!
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("CollectionViewCell", forIndexPath: indexPath) as! CollectionViewCell
cell.backgroundColor = UIColor.blackColor()
cell.textLabel?.text = "\(indexPath.section):\(indexPath.row)"
cell.imageView?.image = UIImage(named: "category")
return cell
}
I already declared CollectionViewCell in storyboard inspector but the error message still occur.
After taking a look at your exception:
2015-07-23 16:16:09.754 XXXXX[24780:465607] * Terminating app due to
uncaught exception 'NSInternalInconsistencyException', reason: 'could
not dequeue a view of kind: UICollectionElementKindCell with
identifier CollectionViewCell - must register a nib or a class for the
identifier or connect a prototype cell in a storyboard' * First throw
call stack:
last part is most important:
must register a nib or a class for the
identifier or connect a prototype cell in a storyboard
Which means that your collection view doesn't have registered your custom cell. To resolve this add following in your viewDidLoad:
var nib = UINib(nibName: "UICollectionElementKindCell", bundle:nil)
self.collectionView.registerNib(nib, forCellReuseIdentifier: "CollectionViewCell")
For Swift 3:
collectionView.register(YourCustomCellClass.self, forCellWithReuseIdentifier: "cell")
In your viewDidLoad() put in this code
collectionView.registerClass(YourCustomCellClass.self, forCellWithReuseIdentifier: "cell")

Why would a registered NIB fail to dequeue?

In my app, I do the following in my setup:
let dataCell = UINib(nibName: kData, bundle: NSBundle.mainBundle())
collectionView.registerNib(nib, forCellWithReuseIdentifier: ALBTableViewCellType.Data.rawValue)
I verified dataCell is not nil.
Then as part of my collectionView, I have this call:
let cell = collectionView.dequeueReusableCellWithReuseIdentifier(ALBTableViewCellType.Data.rawValue, forIndexPath: indexPath) as! UICollectionViewCell
However, as this dequeue is called, I get an error:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle:...
Why won't a registered NIB dequeue? Just to verify, I tried removing the as! UICollectionViewCell and casting it later, but that isn't the issue. It still crashes on the same line with the same error.
You are not giving anywhere near enough information, but basically there are two main possibilities:
There is no such nib as the nib you have registered with the table view.
There is such a nib, but it is incorrectly constructed - it must contain exactly one top-level object, and that object must be a table cell.

Cannot use UITableView registerClass(_, forCellReuseIdentifier: ) to deregister a UITableViewCell

I can register a UITableViewCell with
table.registerClass(SignEntryCell.self, forCellReuseIdentifier: "SignEntry")
The documentation says I should be able to deregister
If you previously registered a class or nib file with the same reuse identifier, the class you specify in the cellClass parameter replaces the old entry. You may specify nil for cellClass if you want to unregister the class from the specified reuse identifier.
But using
table.registerClass(nil, forCellReuseIdentifier: "SignEntry")
gives me the following compiler error message
Cannot invoke 'registerClass' with an argument list of type '(nil, forCellReuseIdentifier: String)'
Does anyone know how to deregister a cell from a table?
The approach(unregister) is unavailable in Swift. You will get a error if you passing a non-UITableViewCell:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException',
reason: 'must pass a class of kind UITableViewCell'
***
The cellClass is not an optional type so you can't pass a nil. In fact, we use almost nothing.
Below code is helpful for you.
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{
var cell:SignEntryCell? = tableView.dequeueReusableCellWithIdentifier("cell") as? SignEntryCell
if (cell==nil)
{
var nib:NSArray=NSBundle.mainBundle().loadNibNamed("SignEntryCell", owner: self, options: nil)
cell = nib.objectAtIndex(0) as? SignEntryCell
}
return true
}
Try this:
self.tableView.registerClass(UITableViewCell().classForCoder, forCellReuseIdentifier: "reuseIdentifier")

Resources