Last active
August 17, 2017 08:23
-
-
Save Dimillian/5ab0b46b540e00f4a6b6a0a5e1165738 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyBooksTableProvider { | |
enum Sections: Int { | |
case reading, menu, booklists | |
static func count() -> Int { | |
return 3 | |
} | |
func headerView() -> UIView? { | |
if self == .reading { | |
return nil | |
} | |
if self == .booklists { | |
// create your custom header view and return it. | |
return view | |
} | |
// some other default custom view. | |
let view = UIView(frame: CGRect(x: 0, y: 0, | |
width: UIScreen.main.bounds.size.width, | |
height: Dimensions.FeedSeparator.normal.rawValue)) | |
view.backgroundColor = .clear | |
return view | |
} | |
func headerHeight() -> CGFloat { | |
if self == .reading { | |
return 0 | |
} | |
if self == .booklists { | |
return 70 | |
} | |
return Dimensions.FeedSeparator.normal.rawValue | |
} | |
} | |
class func numberOfRowsInSection(section: Int) -> Int { | |
let index = Sections(rawValue: section)! | |
switch index { | |
case .reading: | |
return 1 | |
case .menu: | |
return 5 | |
case .booklists: | |
return 0 | |
} | |
} | |
class func cellForRow(parentVC: UIViewController, | |
tableView: UITableView, | |
indexPath: IndexPath, | |
user: String) -> UITableViewCell { | |
let section = Sections(rawValue: indexPath.section)! | |
switch section { | |
case .reading: | |
if let cell = tableView.getCell(forType: ComposeTableViewCell<LibraryViewController>.self) { | |
cell.vc.userId = user | |
cell.parentViewController = parentVC | |
return cell | |
} | |
case .menu: | |
if let cell = tableView.getCell(forType: LabeledTableViewCell.self) { | |
cell.titleLabel.text = MyBooksTableProvider.titlesDatasource[indexPath.row] | |
return cell | |
} | |
case .booklists: | |
return UITableViewCell() | |
} | |
return UITableViewCell() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment