123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- //
- // ThreeViewController.swift
- // OJASwiftKitDemo
- //
- // Created by luxiaoming on 2017/3/8.
- // Copyright © 2017年 luxiaoming. All rights reserved.
- //
- import UIKit
- import OJASwiftKit
- class TESTDataModel: NSObject {
-
- var heightForCell: CGFloat = 44
-
-
- var didSelectCallback: ((IndexPath) -> Void)?
-
- var shouldAutoDeselectCell: Bool = true
-
-
- var title: String = "111"
-
-
-
- // var cellStyle: UITableViewCellStyle = .default
-
- }
- class ThreeViewController: OJSTableViewController {
- var dataArray = [TESTDataModel]()
-
-
- }
- // MARK: - Lifecycle
- extension ThreeViewController {
-
- override func viewDidLoad() {
- super.viewDidLoad()
-
- tableView.delegate = self
- tableView.dataSource = self
- tableView.ojs_registerCell(class: OJSStaticCell.self)
- // tableView.ojs_register(nib: OJSStaticCell.classForCoder())
-
- self.dataArray = [TESTDataModel(), TESTDataModel(), TESTDataModel(), TESTDataModel(),]
-
- }
-
- override func didReceiveMemoryWarning() {
- super.didReceiveMemoryWarning()
- // Dispose of any resources that can be recreated.
- }
- }
- // MARK: - UITableViewDataSource
- extension ThreeViewController: UITableViewDataSource {
-
- func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
- return self.dataArray.count
- }
-
- func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
- let cell = tableView.ojs_dequeueReusableCell(withClass: OJSStaticCell.self)
-
- // let cell = tableView.dequeueReusableCell(withIdentifier: OJSStaticCell.ojs_reuseIdentifier) as! OJSStaticCell
- cell.textLabel?.text = "text"
-
- return cell
- }
-
- }
- // MARK: - UITableViewDelegate
- extension ThreeViewController: UITableViewDelegate {
-
- func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
- return self.dataArray[indexPath.row].heightForCell
- }
-
- func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
- let model = self.dataArray[indexPath.row]
-
- if model.shouldAutoDeselectCell {
- tableView.deselectRow(at: indexPath, animated: true)
- }
-
- if let callback = model.didSelectCallback {
- callback(indexPath)
- }
-
- }
-
- }
- //// MARK: - Rotation
- //extension ThreeViewController {
- //
- // open override var shouldAutorotate: Bool {
- // return true
- // }
- //
- // open override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
- // return .allButUpsideDown
- // }
- //
- // open override var preferredInterfaceOrientationForPresentation: UIInterfaceOrientation {
- // return .landscapeLeft
- // }
- //}
|