Comments (17)
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.
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.
@syky27 Don't worry, let me know if I you have any troubles understanding how it works. Documentation can always be improved ❤️
from datasource.
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.
@swabzz There's a demo showing using DATASource with custom UITableViewCells. Check it out :)
from datasource.
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.
@swabzz Hi, it's most likely something else then. Any chance I can get a sample project to reproduce this one?
from datasource.
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.
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.
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.
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.
Hello @3lvis
Sharing sample project please take a look
testDATASource.zip
from datasource.
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.
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.
Here's the working project.
from datasource.
I hope that was useful! Have a nice week 😁
from datasource.
👍 Working
Thanks for help @3lvis
from datasource.
Related Issues (20)
- No Example to delete items in table-view HOT 2
- Predicate update for DATASource cause crash HOT 2
- Filtering DATASource HOT 2
- Sorting by distance HOT 6
- Pagination HOT 5
- Customizing change animations in Objective C HOT 3
- How to change predicate on fetchrequest? HOT 3
- NSRangeException exception in NSFetchedResultsChangeUpdate event of NSFetchedResultsController HOT 2
- UITableVIew swipe trailingSwipeActionsConfigurationForRowAt not working HOT 4
- sortDescriptors proposal HOT 4
- NSInternalInconsistencyException at controllerDidChangeContent (DATASource+NSFetchedResultsControllerDelegate.swift:137) HOT 5
- Updating core data object causes DATASource to delete from tableView HOT 5
- Invalid Update Crash HOT 1
- Unit test viewForSupplementaryElementOfKind with title HOT 1
- Multiple cell identifier support HOT 7
- TableViewCRUDAndReorder Demo HOT 2
- Demo on multiple cell identifier
- Add a way to disable calling configure cell in cellForItemAt HOT 1
- Assertion failure in -[UITableView _endCellAnimationsWithContext HOT 10
- DidSelectRowAtIndexPath HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from datasource.