crash in core data xcode 8 - ios

i am facing an issue in IOS swift Xcode 8
after i setup my Core Data and before i insert any junk data in purpose of testing the fetch function the app run correctly with no crash and no data but after i insert a data the app crash with below message
Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UITableViewCell 0x7f9b26054c00> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key Deatials.
here is my code
//
import UIKit
import CoreData
// the NSFetchedResultsControllerDelegate needed to start woring in all the function for datacore
class MainVC: UIViewController , UITableViewDelegate, UITableViewDataSource,NSFetchedResultsControllerDelegate{
// definning the main view the table and the segment.
#IBOutlet weak var TableView: UITableView!
#IBOutlet weak var segment: UISegmentedControl!
// need to difine the NSFetchedResultsController to define the remaining 3 functions for the tableview
var controller : NSFetchedResultsController<Item>!
override func viewDidLoad() {
super.viewDidLoad()
generateTeseData()
attemptFetch()
TableView.dataSource = self
TableView.delegate = self
}
// we need to define 3 main fucntions for the table view
func numberOfSections(in tableView: UITableView) -> Int {
if let sections = controller.sections{
return sections.count
}
return 0
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// need to difine number of rows in section by NSFetchedResultsController
if let sections = controller.sections{
let sectionInfo = sections[section]
return sectionInfo.numberOfObjects
}
return 0
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
// linking the cell var with the class of itemCell been created in the View Folder
let cell = tableView.dequeueReusableCell(withIdentifier: "CellItem", for: indexPath) as! ItemCell
// function been created below:
configureCell(cell: cell, indexPath: indexPath as NSIndexPath)
return cell
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 150
}
func configureCell (cell:ItemCell, indexPath: NSIndexPath){
let item = controller.object(at: indexPath as IndexPath)
cell.ConfigureCellsInCellclass(item: item)
}
func attemptFetch () {
let fetchrequest:NSFetchRequest<Item> = Item.fetchRequest()
let datesort = NSSortDescriptor(key: "created", ascending: false)
fetchrequest.sortDescriptors = [datesort]
let controller = NSFetchedResultsController(fetchRequest: fetchrequest, managedObjectContext: context, sectionNameKeyPath: nil, cacheName: nil)
self.controller = controller
do{
try controller.performFetch()
}catch{
let error = error as NSError
print("\(error)")
}
}
// these two function for the update in the tableview
func controllerWillChangeContent(_ controller: NSFetchedResultsController<NSFetchRequestResult>) {
TableView.beginUpdates()
}
func controllerDidChangeContent(_ controller: NSFetchedResultsController<NSFetchRequestResult>) {
TableView.endUpdates()
}
//this function to preforme all the functions for the <Data Core>
func controller(_ controller: NSFetchedResultsController<NSFetchRequestResult>, didChange anObject: Any, at indexPath: IndexPath?, for type: NSFetchedResultsChangeType, newIndexPath: IndexPath?) {
switch(type)
{
case.insert:
if let indexpath = newIndexPath {
TableView.insertRows(at: [indexpath], with: .fade)
}
break
case.delete:
if let indexpath = indexPath{
TableView.deleteRows(at: [indexpath], with: .fade)
}
break
case.update:
if let indexpath = indexPath {
let cell = TableView.cellForRow(at: indexpath) as! ItemCell
configureCell(cell: cell, indexPath: indexPath! as NSIndexPath)
}
break
case.move:
if let indexpath = indexPath {
TableView.deleteRows(at: [indexpath], with: .fade)
}
if let indexpath = indexPath {
TableView.insertRows(at: [indexpath], with: .fade)
}
break
}
}
at this point the system will cun without any crash
but after i add the insert function in below it's start crashing
func generateTeseData(){
let item = Item(context: context)
item.title = "IMAC"
item.price = 2000
item.details = "Soon"
}
this is my view cell file
class ItemCell: UITableViewCell {
// this view to take all the label from the view and link it here
#IBOutlet weak var thump: UIImageView!
#IBOutlet weak var Title: UILabel!
#IBOutlet weak var Price: UILabel!
#IBOutlet weak var Deatials: UILabel!
// using this function to set the values of the items with the labels been linked before in upper section
func ConfigureCellsInCellclass (item:Item){
Title.text = item.title
Price.text = ("$\(item.price)")
Deatials.text = item.details
}
}
thank you guys in advance

As #Larme says your problem is related to IBOutlet which is not reflect in class anymore.
Disconnect bad outlet

Related

How to Perform CRUD operation in TableView Swift

I have written code for performing Delete,Insert,Update . when I execute my code I'm getting an Error like "Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid index path for use with UITableView. Index paths passed to table view must contain exactly two indices specifying the section and row. Please use the category on NSIndexPath in NSIndexPath+UIKitAdditions.h if possible."
I'm adding the code here
import UIKit
class ViewController: UIViewController {
#IBOutlet var tableView: UITableView!
#IBOutlet var Insert: UIButton!
#IBOutlet var txtfield: UITextField!
var index = IndexPath()
var models = ["1.Audi","2.Hyundai","3.Bentley","4.Chevrolet","5.Dodge","6.Electric","7.Ford","8.Genesis","9.Honda","10.Ferrari","11.Nissan","12.Porche","13.Range Rover","14.Lamborgini","15.McLaren","16.koneisegg","17.Volvo","18.Mazda","19.Bmw"]
override func viewDidLoad() {
super.viewDidLoad()
tableView.delegate = self
tableView.dataSource = self
}
#IBAction func textFieldEdit(_ sender: UITextField) {
//self.tableView.reloadData()
if let cell = tableView.cellForRow(at: index) as? UITableViewCell{
cell.textLabel?.text = self.txtfield.text
}
}
#IBAction func insertBtn(_ sender: UIButton) {
if let txt = txtfield.text, !txt.isEmpty{
//self.models.append(txt)
self.models.insert(txt,at: 0)
tableView.beginUpdates()
tableView.insertRows(at: [IndexPath(row: 0, section: 0)], with: .fade)
tableView.endUpdates()
print (models.count)
}
}
}
extension ViewController: UITableViewDataSource,UITableViewDelegate{
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return models.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
cell.textLabel?.text = models[indexPath.row]
return cell
}
func tableView(_ tableView: UITableView, editingStyleForRowAt indexPath: IndexPath) -> UITableViewCell.EditingStyle {
return .delete
}
func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) {
if editingStyle == .delete{
tableView.beginUpdates()
models.remove(at: indexPath.row)
tableView.deleteRows(at: [indexPath], with: .fade)
tableView.endUpdates()
}
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
index = indexPath
self.txtfield.text = models[indexPath.row]
}
}
ScreenShot of My storyBoard
You didn't explain when you're getting the error.
Running your code as-is, no apparent errors.
However, my guess is that you're hitting an issue when you haven't yet selected a row, or when you've done something to change the selection while editing in the text field.
Try changing your textFieldEdit func to this:
#IBAction func textFieldEdit(_ sender: UITextField) {
// make sure
// a row is selected
// and
// we can get a reference to that cell
guard let pth = tableView.indexPathForSelectedRow,
let cell = tableView.cellForRow(at: pth)
else {
return
}
// properly unwrap optional .text property
let str = sender.text ?? ""
// update the data
self.models[pth.row] = str
// update the cell
cell.textLabel?.text = str
}
You've instantiated an IndexPath without properties
var index = IndexPath()
If you refer to it before setting a valid property you'll get that error.
Possible Solution
var index: IndexPath?
Use an optional for your index rather than setting an invalid default property. It'll be nil until you assign an instance.
You'll then have to use index?. or if let index = index when using the property, but it'll be safe.

tabelview RowInSection fatal error swift

I'm a beginner in IOS development in swift. The problem I am facing is: I am building an app using CoreData and the app contains table view and table cell. I can't really explain because of my lack of knowledge so I'm sharing screenshots. I have seen other Questions asked, none of them solved my error. and I have also made a function for context in AppDelegate which is
#available(iOS 10.0, *)
let ad = UIApplication.shared.delegate as! AppDelegate
#available(iOS 10.0, *)
let context = ad.persistentContainer.viewContext
my code for VC is
import UIKit
import CoreData
class MainVC: UIViewController, UITableViewDelegate, UITableViewDataSource, NSFetchedResultsControllerDelegate {
#IBOutlet weak var tableViewmain: UITableView!
#IBOutlet weak var topSegment: UISegmentedControl!
var fetchResultControll: NSFetchedResultsController<Items>!
override func viewDidLoad() {
super.viewDidLoad()
tableViewmain.delegate = self
tableViewmain.dataSource = self
doFetch()
}
func configureCell (cell: ItemsCell, indexPath: IndexPath) {
let item = fetchResultControll.object(at: indexPath) // remember as here
cell.confugringCell(item: item)
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableViewmain.dequeueReusableCell(withIdentifier: "ItemsCell", for: indexPath) as! ItemsCell
configureCell(cell: cell, indexPath: indexPath)
return cell
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if let sections = fetchResultControll.sections{
let sectionInfo = sections[section]
return sectionInfo.numberOfObjects
}
return 0
}
func numberOfSections(in tableView: UITableView) -> Int {
if let allSections = fetchResultControll.sections {
return allSections.count
}
return 0
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 150
}
func doFetch() {
let fetchRequest: NSFetchRequest<Items> = Items.fetchRequest()
let dateSrot = NSSortDescriptor(key: "created", ascending: false)
fetchRequest.sortDescriptors = [dateSrot]
if #available(iOS 10.0, *) {
let controller = NSFetchedResultsController(fetchRequest: fetchRequest, managedObjectContext: context, sectionNameKeyPath: nil, cacheName: nil)
do {
try controller.performFetch()
}
catch {
let err = error as NSError
print("\(err)")
}
} else {
// Fallback on earlier versions
}
}
//controler willchnge
func controllerWillChangeContent(_ controller: NSFetchedResultsController<NSFetchRequestResult>) {
tableViewmain.beginUpdates()
}
//controlerdidchnge
func controllerDidChangeContent(_ controller: NSFetchedResultsController<NSFetchRequestResult>) {
tableViewmain.endUpdates()
}
//controlerdidchangeanobject
func controller(_ controller: NSFetchedResultsController<NSFetchRequestResult>, didChange anObject: Any, at indexPath: IndexPath?, for type: NSFetchedResultsChangeType, newIndexPath: IndexPath?) {
switch(type) {
case .insert:
if let indexpath = newIndexPath {
tableViewmain.insertRows(at: [indexpath], with: .fade)
}
break
case .delete:
if let indexpath = indexPath {
tableViewmain.deleteRows(at: [indexpath], with: .fade)
}
break
case .update:
if let indexpath = indexPath {
let cell = tableViewmain.cellForRow(at: indexpath) as! ItemsCell
configureCell(cell: cell, indexPath: indexpath) // as used here
}
break
case .move:
if let indexpath = indexPath {
tableViewmain.deleteRows(at: [indexpath], with: .fade)
}
if let indexpath = newIndexPath {
tableViewmain.insertRows(at: [indexpath], with: .fade)
}
break
}
}
I hope you understand me.. Any Help would be highly appreciated
Replace following line with your .
var fetchResultControll: NSFetchedResultsController<Items>?

Swift, CoreData: TableView not reloading data when childVC dismissed

Ok I am brand new to this and am a bit overwhelmed going through many tutorials and articles. And spent a few hours sorting through similar issues with no luck in fixing my own. I have a "AddSiteVC" to allow the user to add or delete Items that are put into CoreData and then displayed in a TableView on my "MainVC". My problem is when I press save or delete and get dismissed back to my MainVC onBtnClick the TableView doesn't update until I leave the MainVC and then come back. I don't know what I'm doing wrong but can't seem to find anything that fixes this... I don't know where my problem is so I'll include most of my MainVC code for reference.
Any help would be greatly appreciated!
Thanks!
import UIKit
import CoreData
class SitesViewController: UIViewController, UITableViewDelegate, UITableViewDataSource, NSFetchedResultsControllerDelegate {
#IBOutlet weak var tableView: UITableView!
var controller: NSFetchedResultsController<Sites>!
override func viewDidLoad() {
super.viewDidLoad()
tableView.delegate = self
tableView.dataSource = self
attemptFetch()
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "SitesCell", for: indexPath) as! SitesCell
configureCell(cell: cell, indexPath: indexPath as NSIndexPath)
return UITableViewCell()
}
func configureCell(cell: SitesCell, indexPath: NSIndexPath) {
let sites = controller.object(at: indexPath as IndexPath)
cell.configureCell(sites: sites)
cell.accessoryType = .detailButton
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "AddSiteViewController" {
if let destination = segue.destination as? AddSiteViewController {
if let site = sender as? Sites {
destination.siteToEdit = site
}
}
}
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if let sections = controller.sections {
let sectionInfo = sections[section]
return sectionInfo.numberOfObjects
}
return 0
}
func numberOfSections(in tableView: UITableView) -> Int {
if let sections = controller.sections {
return sections.count
}
return 0
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 75
}
func tableView(_ tableView: UITableView, accessoryButtonTappedForRowWith indexPath: IndexPath) {
if let objs = controller.fetchedObjects, objs.count > 0 {
let site = objs[indexPath.row]
performSegue(withIdentifier: "AddSiteViewController", sender: site)
}
}
func attemptFetch() {
let fetchRequest: NSFetchRequest<Sites> = Sites.fetchRequest()
let alphebaticalSort = NSSortDescriptor(key: "name", ascending: true)
fetchRequest.sortDescriptors = [alphebaticalSort]
let controller = NSFetchedResultsController(fetchRequest: fetchRequest, managedObjectContext: context, sectionNameKeyPath: nil, cacheName: nil)
controller.delegate = self
self.controller = controller
do {
try controller.performFetch()
} catch {
let error = error as NSError
print("\(error)")
}
}
func controllerWillChangeContent(_ controller: NSFetchedResultsController<NSFetchRequestResult>) {
tableView.beginUpdates()
}
func controller(_ controller: NSFetchedResultsController<NSFetchRequestResult>, didChange anObject: Any, at indexPath: IndexPath?, for type: NSFetchedResultsChangeType, newIndexPath: IndexPath?) {
switch (type) {
case.insert:
if let indexPath = newIndexPath {
tableView.insertRows(at: [indexPath], with: .fade)
}
break
case.delete:
if let indexPath = indexPath {
tableView.deleteRows(at: [indexPath], with: .fade)
}
break
case.update:
if let indexPath = indexPath {
let cell = tableView.cellForRow(at: indexPath) as! SitesCell
configureCell(cell: cell, indexPath: indexPath as NSIndexPath)
}
break
case.move:
if let indexPath = indexPath {
tableView.deleteRows(at: [indexPath], with: .fade)
}
if let indexPath = newIndexPath {
tableView.insertRows(at: [indexPath], with: .fade)
}
break
}
}
func controllerDidChangeContent(_ controller: NSFetchedResultsController<NSFetchRequestResult>) {
tableView.endUpdates()
}
}
Please make following change in the code . Because viewDidLoad will be called when viewcontroller is loaded . But as per your requirement you adding something in Modal page. So you need move the code to viewWillAppear
import UIKit
import CoreData
class SitesViewController: UIViewController, UITableViewDelegate, UITableViewDataSource, NSFetchedResultsControllerDelegate {
#IBOutlet weak var tableView: UITableView!
var controller: NSFetchedResultsController<Sites>!
override func viewDidLoad() {
super.viewDidLoad()
tableView.delegate = self
tableView.dataSource = self
}
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
attemptFetch()
}
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "SitesCell", for: indexPath) as! SitesCell
configureCell(cell: cell, indexPath: indexPath as NSIndexPath)
return cell }

delete core data from a row when swipe to delete is activated

Im working on a project in swift 3.0, and i'm populating data on a table view, which I save on a core data entity from another view controller (from two text fields). I wants to delete data when swipe to delete is activated both from my array and core data. my code on UITableView class as bellow.
import Foundation
import UIKit
import CoreData
class MyExpencesViewController: UIViewController,UITableViewDelegate, UITableViewDataSource {
#IBOutlet weak var expensesTableView: UITableView!
var myExpensesArray = [String] ()
var myAmountArray = [String] ()
override func viewDidLoad() {
super.viewDidLoad()
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
loadData()
self.expensesTableView.reloadData()
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return (myExpensesArray.count)
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell: MyExpensesTableViewCell = tableView.dequeueReusableCell(withIdentifier: "cell") as! MyExpensesTableViewCell
cell.myExpenseName.text = myExpensesArray [indexPath.row]
cell.myExpenseAmount.text = myAmountArray [indexPath.row]
return cell
}
func loadData (){
let appDelegate = UIApplication.shared.delegate as! AppDelegate
let context = appDelegate.persistentContainer.viewContext
let request = NSFetchRequest <NSFetchRequestResult> (entityName: "UserExpenses")
request.returnsObjectsAsFaults = false
do {
let results = try context.fetch(request)
// check data existance
if results.count>0 {
print(results.count)
for resultGot in results as! [NSManagedObject]{
if let expName = resultGot.value(forKey:"expenseName") as? String{
myExpensesArray += [expName]
DispatchQueue.main.async {
[unowned self] in self.expensesTableView.reloadData()
self.expensesTableView.reloadData()
}
print("myExp array is : \(myExpensesArray)")
}
if let amountVal = resultGot.value(forKey:"amount") as? String{
myAmountArray += [amountVal]
DispatchQueue.main.async {
[unowned self] in self.expensesTableView.reloadData()
self.expensesTableView.reloadData()
}
print("myAmount array is : \(myAmountArray)")
}
}
}
}catch{
print("No Data to load in the array")
}
}
}
You have to add 2 more methods for delete row on swipe
//For swipe access allow
func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
return true
}
//For remove row from tableview & object from array.
func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
if (editingStyle == UITableViewCellEditingStyle.delete) {
// delete data and row
<YourArray>.remove(at: indexPath.row)
tableView.deleteRows(at: [indexPath], with: .fade)
}
}
let me know if you need more detail.

how to display 2 different prototype cells at different different sizes

UPDATE:
I went a different route. Heres what I would like to do. Design my app that lets me save core data and view it in another console in tableview. Once in the tableview console, I can also see a chart at the top of the console as well.
What I did:
I created a UIViewController, dragged over an imageview just to use that as an example. I also dragged in a tableview, cells...etc.
My Problem:
I can view the blank tableview cells and see the sample image. Once I save the core data and go back to try viewing the data, I get an error. I have the datasource and delegate implemented but, do I need to put that in my code.
class ViewMealsViewController: UIViewController, NSFetchedResultsControllerDelegate {
#IBOutlet weak var tableView: UITableView!
#IBOutlet weak var menuButton: UIBarButtonItem!
let managedObjectContext = (UIApplication.shared.delegate as! AppDelegate).managedObjectContext
var fetchedResultController: NSFetchedResultsController<MealStats> = NSFetchedResultsController()
override func viewDidLoad() {
super.viewDidLoad()
fetchedResultController = getFetchedResultController()
fetchedResultController.delegate = self
do {
try fetchedResultController.performFetch()
} catch _ {
}
if revealViewController() != nil {
revealViewController().rearViewRevealWidth = 325
menuButton.target = revealViewController()
menuButton.action = #selector(SWRevealViewController.revealToggle(_:))
view.addGestureRecognizer(self.revealViewController().panGestureRecognizer())
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
// MARK:- Retrieve Stats
func getFetchedResultController() -> NSFetchedResultsController<MealStats> {
fetchedResultController = NSFetchedResultsController(fetchRequest: taskFetchRequest(), managedObjectContext: managedObjectContext, sectionNameKeyPath: nil, cacheName: nil)
return fetchedResultController
}
func taskFetchRequest() -> NSFetchRequest<MealStats> {
let fetchRequest = NSFetchRequest<MealStats> (entityName: "MealStats")
let timeSortDescriptor = NSSortDescriptor(key: "mealtype",
ascending: true, selector: #selector(NSString.caseInsensitiveCompare(_:)))
let milesSortDescriptor = NSSortDescriptor(key: "mealname",
ascending: true, selector: #selector(NSString.caseInsensitiveCompare(_:)))
fetchRequest.sortDescriptors = [timeSortDescriptor, milesSortDescriptor]
return fetchRequest
}
// MARK: - TableView data source
func numberOfSections(in tableView: UITableView) -> Int {
let numberOfSections = fetchedResultController.sections?.count
return numberOfSections!
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
let numberOfRowsInSection = fetchedResultController.sections?[section].numberOfObjects
return numberOfRowsInSection!
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
let mealstats = fetchedResultController.object(at: indexPath) as! MealStats
cell.textLabel?.text = mealstats.mealtype
cell.detailTextLabel!.text = mealstats.mealname
return cell
}
// MARK: - TableView DeleteĆ’
func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
let managedObject:NSManagedObject = fetchedResultController.object(at: indexPath) as! NSManagedObject
managedObjectContext.delete(managedObject)
do {
try managedObjectContext.save()
} catch _ {
}
}
// MARK: - TableView Refresh
func controllerDidChangeContent(_ controller: NSFetchedResultsController<NSFetchRequestResult>) {
tableView.reloadData()
}
}
UIViewController with a sample image for an example
Error I get once I try to view saved core data in the tableview
Use UITableViewController
add two different cells to tableview on storyboard,
set two unique identifiers for them i.e
Cell No. 1 identifier : iden_1
Cell No. 2 identifier : iden_2
then in your class
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell
if(condition)
{
cell = tableView.dequeueReusableCell(withIdentifier: "iden_1", for: indexPath)
let stats = fetchedResultController.object(at: indexPath) as! Stats
cell.textLabel?.text = stats.type
cell.detailTextLabel!.text = stats.name
}
else{
cell = tableView.dequeueReusableCell(withIdentifier: "iden_2", for: indexPath)
let stats = fetchedResultController.object(at: indexPath) as! Stats
cell.textLabel?.text = stats.type
cell.detailTextLabel!.text = stats.name
}
return cell
}
and use this for identifying height for both cells.
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
if(condition)
return 100
return 200
}

Resources