Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support to use storyboard cell prototype as cell #74

Open
wants to merge 1 commit into
base: 2.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Static/DataSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ public class DataSource: NSObject {
registeredCellIdentifiers.insert(identifier)
if let nib = row.cellClass.nib() {
tableView.registerNib(nib, forCellReuseIdentifier: identifier)
} else {
} else if row.storyboardCellIdentifier == nil {
// Only register when we are not using storyboard cell identifier. Registering will cause the prototype cell not to be loaded and assume that we are using custom class
tableView.registerClass(row.cellClass, forCellReuseIdentifier: identifier)
}
}
Expand Down
11 changes: 8 additions & 3 deletions Static/Row.swift
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ public struct Row: Hashable, Equatable {

/// Actions to show when swiping the cell, such as Delete.
public var editActions: [EditAction]

/// Cell identifier from storyboard
public var storyboardCellIdentifier: String?

var canEdit: Bool {
return editActions.count > 0
Expand All @@ -123,7 +126,8 @@ public struct Row: Hashable, Equatable {
}

var cellIdentifier: String {
return cellClass.description()
// Storyboard cell identifier have precedence
return storyboardCellIdentifier ?? cellClass.description()
}

public var hashValue: Int {
Expand All @@ -134,8 +138,8 @@ public struct Row: Hashable, Equatable {
// MARK: - Initializers

public init(text: String? = nil, detailText: String? = nil, selection: Selection? = nil,
image: UIImage? = nil, accessory: Accessory = .None, cellClass: CellType.Type? = nil, context: Context? = nil, editActions: [EditAction] = [], UUID: String = NSUUID().UUIDString) {

image: UIImage? = nil, accessory: Accessory = .None, cellClass: CellType.Type? = nil, storyboardCellIdentifier: String? = nil, context: Context? = nil, editActions: [EditAction] = [], UUID: String = NSUUID().UUIDString, backgroundColor: UIColor? = nil) {
self.UUID = UUID
self.text = text
self.detailText = detailText
Expand All @@ -145,6 +149,7 @@ public struct Row: Hashable, Equatable {
self.cellClass = cellClass ?? Value1Cell.self
self.context = context
self.editActions = editActions
self.storyboardCellIdentifier = storyboardCellIdentifier
}
}

Expand Down