Giter Club home page Giter Club logo

Comments (17)

3lvis avatar 3lvis commented on July 17, 2024

Hi Tomas,

Not stupid at all. You just need to send the cell identifier of your custom registered cell.

Example:

Registered CustomCell, that's a subclass of UITableViewCell.

self.tableView.registerClass(CustomCell.self, forCellReuseIdentifier: CustomCell.Identifier)

Then you create your DATASource like this:

let dataSource = DATASource(tableView: self.tableView, cellIdentifier: CustomCell.Identifier, fetchRequest: request, mainContext: self.dataStack!.mainContext, sectionName: "firstLetterOfName", configuration: { cell, item, indexPath in
    if let cell = cell as? CustomCell {
        cell.label.text = item.valueForKey("name") as? String
    }
})

self.tableView.dataSource = self.dataSource

Let me know if this works for you, otherwise feel free to reopen the issue :)

from datasource.

syky27 avatar syky27 commented on July 17, 2024

That's exactly how I have it, so I double checked and I figured out that I had one more if above the assignation to cell, which was taking objects from database and casting them, and that's where it failed... (Just smashing my head agains wall, how stupid I am)

Thank you, sorry for wasting your time.

from datasource.

3lvis avatar 3lvis commented on July 17, 2024

@syky27 Don't worry, let me know if I you have any troubles understanding how it works. Documentation can always be improved ❤️

from datasource.

swabzz avatar swabzz commented on July 17, 2024

Hello,
I registered CustomCell, that's a subclass of UITableViewCell.
But when assigning the value to label of subclass its giving me fatal error for nil variables
as
fatal error: unexpectedly found nil while unwrapping an Optional value

here is my code..

{
self.dataStack = DATAStack(modelName: "modelname")
self.tableView.register(NotificationsTableViewCell.self, forCellReuseIdentifier: "NotificationsTableViewCellIdentifier")
self.tableView.dataSource = self.dataSource
}

lazy var dataSource: DATASource = {
let request: NSFetchRequest = NSFetchRequest(entityName: "Requests")
request.sortDescriptors = [NSSortDescriptor(key: "request_id", ascending: true)]

    let dataSource = DATASource(tableView: self.tableView, cellIdentifier: "NotificationsTableViewCellIdentifier", fetchRequest: request, mainContext: self.dataStack!.mainContext, configuration: { cell, item, indexPath in
        
        if let cell = cell as? NotificationsTableViewCell {
            cell.TitleLabel.text = item.value(forKey: "title") as? String
            cell.RequestIdLabel.text = item.value(forKey: "request_id") as? String!
            cell.RequestTimeLabel.text = item.value(forKey: "requestTime") as? String!
        }
    })
    return dataSource
}()

Thanks in advance!!

from datasource.

3lvis avatar 3lvis commented on July 17, 2024

@swabzz There's a demo showing using DATASource with custom UITableViewCells. Check it out :)

https://github.com/SyncDB/DATASource/blob/master/SwiftDemo/TableViewController/TableViewController.swift

from datasource.

swabzz avatar swabzz commented on July 17, 2024

Thanks for quick reply @3lvis

I tried same but getting same error

fatal error: unexpectedly found nil while unwrapping an Optional value

My custom cell

class NotificationsTableViewCell: UITableViewCell {

@IBOutlet weak var NotificationIcon: UIImageView!
@IBOutlet weak var TitleLabel: UILabel!
@IBOutlet weak var RequestIdLabel: UILabel!
@IBOutlet weak var RequestTimeLabel: UILabel!

func configureItem(item: Requests) {
    TitleLabel.text = item.title
    RequestIdLabel.text = "\(item.request_id)"
    RequestTimeLabel.text = item.nCode
}

override func setSelected(_ selected: Bool, animated: Bool) {
    super.setSelected(selected, animated: animated)
    if selected {
        setSelected(false, animated: false)
    }
}

}

from datasource.

3lvis avatar 3lvis commented on July 17, 2024

@swabzz Hi, it's most likely something else then. Any chance I can get a sample project to reproduce this one?

from datasource.

swabzz avatar swabzz commented on July 17, 2024

Okay here is the code then,

import DATAStack
import DATASource

//UIViewController
class NotificationsViewController: UIViewController {

@IBOutlet weak var tableView: UITableView!

// MARK: Private
var dataStack: DATAStack!

lazy var dataSource: DATASource = {
    let request: NSFetchRequest = NSFetchRequest<NSFetchRequestResult>(entityName: "Requests")
    request.sortDescriptors = [NSSortDescriptor(key: "request_id", ascending: true)]
    
    let dataSource = DATASource(tableView: self.tableView, cellIdentifier: "NotificationsTableViewCellIdentifier", fetchRequest: request, mainContext: self.dataStack!.mainContext, configuration: { cell, item, indexPath in
        
        let cell = cell as! NotificationsTableViewCell
        cell.TitleLabel.text = item.value(forKey: "title") as? String
        cell.RequestIdLabel.text = item.value(forKey: "request_id") as? String
        cell.RequestTimeLabel.text = item.value(forKey: "requestTime") as? String
        
    })
    return dataSource
}()

override func viewDidLoad() {
    super.viewDidLoad()
    
    self.dataStack = DATAStack(modelName: "xenian")
    self.tableView.register(NotificationsTableViewCell.self, forCellReuseIdentifier: "NotificationsTableViewCellIdentifier")
    self.tableView.dataSource = self.dataSource
}

}

//CUSTOM CELL

class NotificationsTableViewCell: UITableViewCell {

@IBOutlet weak var NotificationIcon: UIImageView!
@IBOutlet weak var TitleLabel: UILabel!
@IBOutlet weak var RequestIdLabel: UILabel!
@IBOutlet weak var RequestTimeLabel: UILabel!

func configureItem(item: Requests) {
TitleLabel.text = item.title
RequestIdLabel.text = "(item.request_id)"
RequestTimeLabel.text = item.nCode
}

override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
if selected {
setSelected(false, animated: false)
}
}
}

CAN YOU REPRODUCE IT USING ABOVE CODE PLEASE???

from datasource.

3lvis avatar 3lvis commented on July 17, 2024

Hi @swabzz,

I'm afraid that doesn't help. I can't find a way to reproduce the crash with that code. Could you send me a Xcode project that I can use?

from datasource.

swabzz avatar swabzz commented on July 17, 2024

Can you check in above project where i am missing proper coding please??
sharing full project is just impossible for me its huge lines of code :-)

from datasource.

swabzz avatar swabzz commented on July 17, 2024

Hi,

I gone through your demo here .. https://github.com/SyncDB/DATASource/tree/master/SwiftDemo
you are not using storyboard i think.

is it possible to use library with storyboard custom uicollection view subclass???

from datasource.

swabzz avatar swabzz commented on July 17, 2024

Hello @3lvis

Sharing sample project please take a look
testDATASource.zip

from datasource.

3lvis avatar 3lvis commented on July 17, 2024

Hi @swabzz,

Thanks for the sample project, it was very helpful.

Remove the cell registration from viewDidLoad and it works fine

    override func viewDidLoad() {
        super.viewDidLoad()
        
        self.dataStack = DATAStack(modelName: "testDATASource")
        self.tableView.dataSource = self.dataSource
    }

from datasource.

3lvis avatar 3lvis commented on July 17, 2024

You also need to remove the override of init?(coder).

import UIKit

class NotificationsTableViewCell: UITableViewCell {
    
    public static let Identifier = "NotificationsTableViewCellIdentifier"
    
    @IBOutlet weak var NotificationIcon: UIImageView!
    @IBOutlet weak var TitleLabel: UILabel!
    @IBOutlet weak var RequestIdLabel: UILabel!
    @IBOutlet weak var RequestTimeLabel: UILabel!
}

from datasource.

3lvis avatar 3lvis commented on July 17, 2024

Here's the working project.

FixedtestDATASource.zip

from datasource.

3lvis avatar 3lvis commented on July 17, 2024

I hope that was useful! Have a nice week 😁

from datasource.

swabzz avatar swabzz commented on July 17, 2024

👍 Working
Thanks for help @3lvis

from datasource.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.