Swift 'unable to dequeue a cell with identifier intervalCellIdentifier
1. With XIB file
You have to register the cell to table first, may be in viewDidLoad
, as:
let nib = UINib(nibName: "CustomCell", bundle: NSBundle.mainBundle())
tableView.registerNib(nib, forCellReuseIdentifier: "CustomCellIdentifier")
This is applicable if we are using a custom cell with .xib
file.
2. Without XIB file
And here is a solution if we are not creating separate .xib
file for custom cell:
We need to create dynamic prototype for cell in table view as:
Then we need to provide class name and reuse identifier for our custom cell as:
Here, no need to register class or nib!
Here is the cellForRowAtIndexPath
implementation:
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
// Configure the cell...
let cell = tableView.dequeueReusableCellWithIdentifier("CustomTableViewCellId", forIndexPath: indexPath) as! CustomTableViewCell
cell.setCellIndexLabel(indexPath.row)
return cell
}
This implementation will be same for both the above solutions.
3. Only Class Implementation
Without XIB, without Dynamic Prototype
Here is the custom cell without any XIB or Dynamic Prototype:
class WithoutNibCustomTableViewCell: UITableViewCell {
override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
//do custom initialisation here, if any
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
override func setSelected(selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
class func identifier() -> String {
return "WithoutNibCustomTableViewCellId"
}
//MARK: Public Methods
func setCellIndexLabel(index: Int) {
let customLbl = UILabel(frame: CGRectMake(0, 0, 100, 40))
customLbl.text = String(index)
contentView.addSubview(customLbl)
}
}
Then, in table view, we need to register cell class as:
tableView!.registerClass(WithoutNibCustomTableViewCell.classForCoder(), forCellReuseIdentifier: WithoutNibCustomTableViewCell.identifier())
cellForRowAtIndexPath
also same as above, like:
let cell = tableView.dequeueReusableCellWithIdentifier(WithoutNibCustomTableViewCell.identifier(), forIndexPath: indexPath) as! WithoutNibCustomTableViewCell
cell.setCellIndexLabel(indexPath.row)
return cell
unable to dequeue a cell with identifier cell with properly defined identifier
It seems that issue was in custom library i was using for navigation. Instead initialising view controller from storyboard identifier, it was initialising class directly, thus storyboard view controller was useless.
Everything works well now.
Trouble with simple TableView in Swift, error SIGNAL SIGART
You did not added the Prototype Cell into the Table View, Drag and Drop the table view cell into the table view and connect the Table View Cell class to it with particular identifier.
Drag and Drop a TableView Cell and Assign a class:
Assign the identifier to it:
Set the Table Style to Basic
Cell reuse identifier in nib does not match the identifier
Looking at the crash -
It looks like -
CustomTableViewCell.xib
has theCutomTableViewCell
value in the reuse identifier.- When you did the
tableView.registerNib
call, you usedCustomTableViewCell
in the reuse identifier.
These reuse identifier values must match.
iOS9 beta - SKEffectNode/CIFilter bug?
I reported the issue to Apple. It was a bug and they fixed it with iOS9 beta 5.
Screen is blank white when started on the Xcode simulator [swift 3.0]
Vertex Shaders
generally run directly on the GPU for which it's compiled. In this case the iOS
simulator doesn't physically have the GPU it needs to work with, hence the white screen.
Usually if you run the code on the physical device it should work, so try running there. Also check out this other question/answer with a similar error that might be of interest.
A vertex shader is simply a tiny program that runs on the GPU, written
in a C++ like language called the Metal Shading Language.
↳ Metal Shading Language Specification
Related Topics
Load Image from Url on Watchkit
Pod Install Gpuimage Does Not Work
Realm Swift: Always Put Nil Values Last in Sort
Global Var VS Shared Instance Swift
Swiftui: How to Only Run Code When the User Stops Typing in a Textfield
Define Struct That Is Treated Like a Class in Swift
Optional Type 'Bool' Cannot Be Used as a Boolean; Test for '!=Nil' Instead
How to Properly Check If Non-Optional Return Value Is Valid
How to Delete Item from Collection View
Swift 2: Invalid Conversion from Throwing Function of Type to Non-Throwing Function
How to Get Core Data Entity by It's Objectid
What's Wrong with My #If Target_Os_Simulator Code for Realm Path Definition
Swift - Kvo - Change.Newvalue and Change.Oldvalue Are Nil
Ios-Charts Set Maximum Visible X Axis Values
Swiftui Pick a Value from a List with Ontap Gesture
Unit Testing Wknavigationdelegate Functions
Swift 3 Warning: Non-Optional Expression of Type 'String' Used in a Check for Optionals