UserViewController.swift
7.08 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
//
// UserViewController.swift
// YouerLiveVideo
//
// Created by 左丞 on 2017/5/16.
// Copyright © 2017年 左丞. All rights reserved.
//
import UIKit
class UserViewController: UIViewController {
@IBOutlet weak var historyList: UITableView!
@IBOutlet weak var userName: UILabel!
@IBOutlet weak var userPhoto: UIImageView!
var historyType:[String] = ["资源历史","微课历史"]
var myResourceType:[String] = ["我的资源","我的微课"]
var sectionList:[String] = ["历史记录","我的"]
var isCloseHistoryList:Bool = false
var isCloseMyResource:Bool = false
var user = AppDelegate.instance().accountManager
override func viewDidLoad() {
super.viewDidLoad()
self.configTheme()
self.navigationItem.rightBarButtonItem = UIBarButtonItem(image: #imageLiteral(resourceName: "icon_setting"), style: .plain, target: self, action: #selector(UserViewController.editBtnClick))
self.automaticallyAdjustsScrollViewInsets = false
setUserInfor()
NotificationCenter.default.addObserver(self, selector: #selector(UserViewController.setUserInfor), name: NSNotification.Name(rawValue: "refreshFirstVC"), object: nil)
// Do any additional setup after loading the view.
}
func setUserInfor(){
userPhoto.layer.cornerRadius = userPhoto.frame.size.height/2
userPhoto.layer.masksToBounds = true
userName.text = user.name()
userPhoto.sd_setImage(with: URL(string: user.photo()), placeholderImage: #imageLiteral(resourceName: "defphoto.png"))
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func userEditClcik(_ sender: Any) {
if user.isOnline(){
let vc = Story.instantiateViewControllerWithIdentifier("UserEditViewControllerVC", storyName: "User") as! UserEditViewController
vc.title = "个人信息"
self.navigationController?.pushViewController(vc, animated: true)
}else{
let vc=Story.instantiateViewControllerWithIdentifier("NewLoginViewControllerVC", storyName: "Login") as! NewLoginViewController
self.present(vc, animated: true, completion: nil)
}
}
func editBtnClick(){
let vc = Story.instantiateViewControllerWithIdentifier("AppSettingViewControllerVC", storyName: "User") as! AppSettingViewController
vc.title = "设置"
self.navigationController?.pushViewController(vc, animated: true)
}
func headerTap(tap:UITapGestureRecognizer){
if tap.view?.tag == 200{
isCloseHistoryList = !isCloseHistoryList
}else{
isCloseMyResource = !isCloseMyResource
}
historyList.reloadData()
}
// override func viewWillAppear(_ animated: Bool) {
// super.viewWillAppear(animated)
// self.tabBarController?.tabBar.isHidden = false
// }
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}
*/
}
extension UserViewController:UITableViewDelegate,UITableViewDataSource{
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let vc = Story.instantiateViewControllerWithIdentifier("HistoryViewControllerVC", storyName: "User") as! HistoryViewController
vc.type = indexPath.row
vc.isHistory = indexPath.section
vc.title = historyType[indexPath.row]
self.navigationController?.pushViewController(vc, animated: true)
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! UserCenterHistoryCell
if indexPath.section == 0{
cell.titleName.text = historyType[indexPath.row]
}else if indexPath.section == 1{
cell.titleName.text = myResourceType[indexPath.row]
}
return cell
}
func numberOfSections(in tableView: UITableView) -> Int {
if user.roletype() == 3 || user.roletype() == 4 || user.roletype() == 5{
return 1
}
return sectionList.count
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if section == 0{
if isCloseHistoryList{
return 0
}
return historyType.count
}else if section == 1{
if isCloseMyResource{
return 0
}
return myResourceType.count
}else{
return 0
}
}
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let headerView = UIView(frame: CGRect(x: 0, y: 0, width: getScreenWidth(), height: 44))
headerView.backgroundColor = UIColor.white
let label = UILabel(frame: CGRect(x: 8, y: headerView.frame.height/2-10, width: 100, height: 21))
label.text = sectionList[section]
label.sizeToFit()
headerView.addSubview(label)
let image = UIImageView(frame: CGRect(x: 0, y: 0, width: 9, height: 15))
image.center = CGPoint(x: getScreenWidth() - 20, y: headerView.frame.height/2)
image.image = #imageLiteral(resourceName: "arrow")
image.isUserInteractionEnabled = true
var angle:Double = 0
if !isCloseHistoryList && section == 0{
angle = M_PI_2
}
if !isCloseMyResource && section == 1{
angle = M_PI_2
}
image.transform = CGAffineTransform(rotationAngle: CGFloat(angle))
headerView.addSubview(image)
let line = UILabel(frame: CGRect(x: 0, y: headerView.frame.height-1, width: getScreenWidth(), height: 1))
line.backgroundColor = historyList.backgroundColor
headerView.addSubview(line)
headerView.tag = 200+section
headerView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(UserViewController.headerTap(tap:))))
return headerView
}
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return 44
}
func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
return 15
}
func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
let view = UIView(frame: CGRect(x: 0, y: 0, width: getScreenWidth(), height: 15))
view.backgroundColor = UIColor.clear
return view
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
self.tabBarController?.tabBar.isHidden = false
}
}
class UserCenterHistoryCell:UITableViewCell{
@IBOutlet weak var titleName: UILabel!
}