I've been trying to use Custom Table cell in my swift app, and faced a problem: My application crashes when I run my app.
My custom table cell class is SimpleTableCell (Objective-C class)
and my cellForRowAtIndexPath
method (swift) is:
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{
let cell = tableView.dequeueReusableCellWithIdentifier("SimpleTableItem", forIndexPath: indexPath)
let data = TableData[indexPath.row]
cell.textLabel?.text = data.description
if (data.image == nil)
{
cell.imageView?.image = UIImage(named:"image.jpg")
load_image(image_base_url + data.imageurl!, imageview: cell.imageView!, index: indexPath.row)
}
else
{
cell.imageView?.image = TableData[indexPath.row].image
}
return cell
}
My app crashes with the error: unable to dequeue a cell with identifier SimpleTableItem - must register a nib or a class for the identifier or connect a prototype cell in a storyboard
What does it mean?
In the storyboard, select your tableView cell and in the attributes inspector, set the identifier to "SimpleTableItem". Hope this helps
dequeueReusableCellWithIdentifier
is trying to find a cell with the identifier "SimpleTableItem"
, but it seems that you haven't given a cell that identifier anywhere. One way to do this is to choose a cell in the Table View in Storyboard, go to the Attributes Inspector and set its identifier to SimpleTableItem
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.