/
CategoryViewController.swift
74 lines (58 loc) · 2.5 KB
/
CategoryViewController.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
//
// CategoryViewController.swift
// Gank
//
// Created by 叶帆 on 2016/10/27.
// Copyright © 2016年 Suzhou Coryphaei Information&Technology Co., Ltd. All rights reserved.
//
import UIKit
final class CategoryViewController: BaseViewController {
var categoryArray: [String] = []
@IBOutlet weak var categoryCollectionView: UICollectionView! {
didSet {
categoryCollectionView.registerNibOf(CategoryCollectionCell.self)
}
}
deinit {
categoryCollectionView?.delegate = nil
gankLog.debug("deinit CategoryViewController")
}
override func viewDidLoad() {
super.viewDidLoad()
categoryArray = GankUserDefaults.version.value! ? ["all", "iOS", "Android", "前端", "瞎推荐", "拓展资源", "App", "休息视频", "福利"] : ["all", "iOS", "前端", "瞎推荐", "拓展资源", "App", "休息视频", "福利"] // 审核,禁止 Android
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
guard let identifier = segue.identifier else {
return
}
switch identifier {
case "showArticle":
let vc = segue.destination as! ArticleViewController
let categoryString = sender as! String
vc.category = categoryString
default:
break
}
}
@IBAction func showSearch(_ sender: Any) {
self.performSegue(withIdentifier: "showSearch", sender: nil)
}
}
extension CategoryViewController: UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout {
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return categoryArray.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell: CategoryCollectionCell = collectionView.dequeueReusableCell(forIndexPath: indexPath)
cell.configure(categoryArray[indexPath.row])
return cell
}
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
collectionView.deselectItem(at: indexPath, animated: true)
if categoryArray[indexPath.row] == "福利" {
self.performSegue(withIdentifier: "showMeizi", sender: nil)
} else {
self.performSegue(withIdentifier: "showArticle", sender: categoryArray[indexPath.row])
}
}
}