This repository was archived by the owner on Sep 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 52
/
Copy pathSubredditListViewController.swift
59 lines (48 loc) · 2.12 KB
/
SubredditListViewController.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
//
// SubredditListCategoryViewController.swift
// reddift
//
// Created by sonson on 2015/10/26.
// Copyright © 2015年 sonson. All rights reserved.
//
import UIKit
/**
View controller to show subreddits that are obtained from redditlist.com or api.reddift.com.
This controller is used newsokur and hierarchical list of redditlist.com.
*/
class SubredditListViewController: UITableViewController {
var list: [SubredditListItem] = []
@IBAction func close(sender: AnyObject) {
dismiss(animated: true, completion: nil)
}
override func viewDidLoad() {
super.viewDidLoad()
tableView.register(SubredditListViewSubtitleCell.self, forCellReuseIdentifier: "Cell")
let barbutton = UIBarButtonItem(barButtonSystemItem: .done, target: self, action: #selector(SubredditListViewController.close(sender:)))
self.navigationItem.rightBarButtonItem = barbutton
}
override func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return list.count
}
override func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
return 44
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let item = list[indexPath.row]
NotificationCenter.default.post(name: SubredditSelectTabBarControllerDidOpenSubredditName, object: nil, userInfo: ["subreddit":item.subreddit])
dismiss(animated: true, completion: nil)
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath as IndexPath)
let item = list[indexPath.row]
if let cell = cell as? SubredditListViewSubtitleCell {
cell.textLabel?.text = item.subreddit
cell.detailTextLabel?.text = item.title
cell.detailTextLabel?.textColor = UIColor.gray
}
return cell
}
}