NewsListViewController.swift 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. //
  2. // NewsListViewController.swift
  3. // xingchuangke
  4. //
  5. // Created by Virgil on 2019/4/17.
  6. // Copyright © 2019 Virgil. All rights reserved.
  7. //
  8. import UIKit
  9. class NewsListViewController: BaseViewController, UITableViewDelegate, UITableViewDataSource {
  10. @IBOutlet weak var tableView: UITableView!
  11. override func viewDidLoad() {
  12. super.viewDidLoad()
  13. initNavLeftBackButton()
  14. self.title = "系统消息"
  15. tableView.register(UINib(nibName: "NewsListTableViewCell", bundle: nil), forCellReuseIdentifier: "NewsListTableViewCell")
  16. tableView.delegate = self
  17. tableView.dataSource = self
  18. tableView.separatorStyle = .none
  19. tableView.showsVerticalScrollIndicator = false
  20. tableView.estimatedRowHeight = 100
  21. tableView.mj_header = MJRefreshNormalHeader(refreshingBlock: {[weak self] in
  22. self!.currentPage = 1
  23. self!.loadData()
  24. })
  25. tableView.mj_header?.lastUpdatedTimeKey = "ShowTableViewCell"
  26. tableView.mj_footer = MJRefreshBackNormalFooter(refreshingBlock: {[weak self] in
  27. self!.currentPage += 1
  28. self!.loadData()
  29. })
  30. tableView.mj_header?.beginRefreshing()
  31. }
  32. // MARK: =============加载数据===============
  33. func loadData() {
  34. let url = RequestURL.messagePageList
  35. let params = NSMutableDictionary()
  36. loadDataList(url: url, params: params, tableView: self.tableView, tag: 1001)
  37. }
  38. override func returnData(tag: Int) {
  39. if tag == 1001 {
  40. tableView.reloadData()
  41. }
  42. }
  43. override func returnError(tag: Int, type: String) {
  44. }
  45. // MARK: TABLEVLEW 实现
  46. func numberOfSections(in tableView: UITableView) -> Int {
  47. return 1
  48. }
  49. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  50. return self.arrData.count
  51. }
  52. func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
  53. return 140
  54. }
  55. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  56. let cell = tableView.dequeueReusableCell(withIdentifier: "NewsListTableViewCell", for: indexPath as IndexPath) as! NewsListTableViewCell
  57. let type = getIntValue(current: indexPath.row, key: "type")
  58. if type == 0 {
  59. cell.lblTitle.text = "系统消息"
  60. } else {
  61. cell.lblTitle.text = "系统公告"
  62. }
  63. cell.lblContent.text = getString(current: indexPath.row, key: "title")
  64. cell.lblDate.text = getString(current: indexPath.row, key: "send_time")
  65. return cell
  66. }
  67. func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
  68. if indexPath.row >= arrData.count {
  69. return
  70. }
  71. let vc = CommonWebViewViewController()
  72. vc.strTitle = "详情"//getString(current: indexPath.row, key: "title");
  73. vc.url = getString(current: indexPath.row, key: "detailWeb")
  74. toViewController(viewController: vc)
  75. }
  76. override func viewWillAppear(_ animated: Bool) {
  77. super.viewWillAppear(animated)
  78. }
  79. override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
  80. super.init(nibName: "NewsListViewController", bundle: nil)
  81. }
  82. required init?(coder aDecoder: NSCoder) {
  83. fatalError("init(coder:) has not been implemented")
  84. }
  85. }