Skip to content

Commit

Permalink
fixed new question reload bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Zrzzzz committed Dec 3, 2020
1 parent 48318b7 commit c2bbee4
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 35 deletions.
8 changes: 4 additions & 4 deletions WePeiYang.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -2470,7 +2470,7 @@
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 202012011630;
CURRENT_PROJECT_VERSION = 202012032200;
DEVELOPMENT_TEAM = A4JNABY964;
GCC_C_LANGUAGE_STANDARD = gnu11;
INFOPLIST_FILE = WePeiYangWidget/Info.plist;
Expand Down Expand Up @@ -2506,7 +2506,7 @@
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 202012011630;
CURRENT_PROJECT_VERSION = 202012032200;
DEVELOPMENT_TEAM = A4JNABY964;
GCC_C_LANGUAGE_STANDARD = gnu11;
INFOPLIST_FILE = WePeiYangWidget/Info.plist;
Expand Down Expand Up @@ -2647,7 +2647,7 @@
CODE_SIGN_IDENTITY = "Apple Development";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 202012011630;
CURRENT_PROJECT_VERSION = 202012032200;
DEVELOPMENT_TEAM = A4JNABY964;
INFOPLIST_FILE = WePeiYang/main/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
Expand Down Expand Up @@ -2676,7 +2676,7 @@
CODE_SIGN_IDENTITY = "Apple Development";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 202012011630;
CURRENT_PROJECT_VERSION = 202012032200;
DEVELOPMENT_TEAM = A4JNABY964;
INFOPLIST_FILE = WePeiYang/main/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
Expand Down
36 changes: 26 additions & 10 deletions WePeiYang/FeedBack/Controller/FBNewQuestionController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ class FBNewQuestionViewController: UIViewController, UITextFieldDelegate, UIText
var tagSelectionView: SelectionView!
var tagDesLabel: UILabel!
// 问题描述
var contentsLabel: UILabel!
var contentCountLabel: UILabel!
var contentLabel: UILabel!
var contentField: UITextView!
// 插入图片
var photoLabel: UILabel!
Expand Down Expand Up @@ -166,16 +167,26 @@ extension FBNewQuestionViewController {

addSymmetryLine(y: 235, isDotted: true)

contentsLabel = UILabel()
contentsLabel.text = "问题描述:"
contentsLabel.textColor = UIColor.black
contentsLabel.font = .systemFont(ofSize: LABEL_FONT_SIZE)
view.addSubview(contentsLabel)
contentsLabel.snp.makeConstraints { (make) in
contentLabel = UILabel()
contentLabel.text = "问题描述:"
contentLabel.textColor = UIColor.black
contentLabel.font = .systemFont(ofSize: LABEL_FONT_SIZE)
view.addSubview(contentLabel)
contentLabel.snp.makeConstraints { (make) in
make.top.equalTo(tagDesLabel.snp.bottom).offset(20)
make.left.equalTo(LEFT_PADDING)
}

contentCountLabel = UILabel()
contentCountLabel.text = "0/200"
contentCountLabel.textColor = .gray
contentCountLabel.font = .systemFont(ofSize: LABEL_FONT_SIZE - 2)
view.addSubview(contentCountLabel)
contentCountLabel.snp.makeConstraints { (make) in
make.centerY.equalTo(contentLabel)
make.right.equalTo(view.snp.right).offset(-LEFT_PADDING)
}

contentField = UITextView()
contentField.layer.borderWidth = 1
contentField.layer.cornerRadius = 5
Expand All @@ -188,7 +199,7 @@ extension FBNewQuestionViewController {
contentField.font = .systemFont(ofSize: 14)
view.addSubview(contentField)
contentField.snp.makeConstraints{ (make) in
make.top.equalTo(contentsLabel.snp.bottom).offset(10)
make.top.equalTo(contentLabel.snp.bottom).offset(10)
make.height.equalTo(100)
make.left.equalTo(LEFT_PADDING)
make.right.equalTo(-LEFT_PADDING)
Expand Down Expand Up @@ -282,8 +293,10 @@ extension FBNewQuestionViewController {
case .success(let questionId):
if let imgs = self.photoCollectionView.images {
guard imgs.count != 1 else {
NotificationCenter.default.post(Notification(name: Notification.Name(FB_NOTIFICATIONFLAG_HAD_SEND_QUESTION)))
NotificationCenter.default.post(Notification(name: Notification.Name(FB_NOTIFICATIONFLAG_NEED_RELOAD)))
NotificationCenter.default.post(Notification(name: Notification.Name(FB_SHOULD_RELOAD_NEWQUESTIONVC)))
SwiftMessages.hideLoading()
SwiftMessages.showSuccessMessage(body: "发布成功")
self.dismiss(animated: true)
return
}
Expand All @@ -305,8 +318,10 @@ extension FBNewQuestionViewController {
}
}
group.notify(queue: .main) {
NotificationCenter.default.post(Notification(name: Notification.Name(FB_NOTIFICATIONFLAG_HAD_SEND_QUESTION)))
NotificationCenter.default.post(Notification(name: Notification.Name(FB_NOTIFICATIONFLAG_NEED_RELOAD)))
NotificationCenter.default.post(Notification(name: Notification.Name(FB_SHOULD_RELOAD_NEWQUESTIONVC)))
SwiftMessages.hideLoading()
SwiftMessages.showSuccessMessage(body: "发布成功")
self.dismiss(animated: true)
}
}
Expand Down Expand Up @@ -345,6 +360,7 @@ extension FBNewQuestionViewController {
let currentString: NSString = textView.text! as NSString
let newString: NSString =
currentString.replacingCharacters(in: range, with: text) as NSString
contentCountLabel.text = "\(newString.length)/200"
return newString.length <= maxLength
}

Expand Down
12 changes: 10 additions & 2 deletions WePeiYang/FeedBack/Controller/FeedBackDetailViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,11 @@ extension FeedBackDetailViewController {
}

@objc func likeOrDislike() {
NotificationCenter.default.post(Notification(name: Notification.Name(FB_NOTIFICATIONFLAG_NEED_RELOAD)))
if self.isLiked ?? false {
if let count = (tableView.tableHeaderView as? FBDetailHeaderView)?.likesLabel.text {
(tableView.tableHeaderView as? FBDetailHeaderView)?.likesLabel.text = String((Int(count) ?? 0) - 1)
}
FBQuestionHelper.dislikeQuestion(id: questionOfthisPage?.id ?? 0) { (result) in
switch result {
case .success(let str):
Expand All @@ -119,6 +123,9 @@ extension FeedBackDetailViewController {
}
}
} else {
if let count = (tableView.tableHeaderView as? FBDetailHeaderView)?.likesLabel.text {
(tableView.tableHeaderView as? FBDetailHeaderView)?.likesLabel.text = String((Int(count) ?? 0) + 1)
}
FBQuestionHelper.likeQuestion(id: questionOfthisPage?.id ?? 0) { (result) in
switch result {
case .success(let str):
Expand Down Expand Up @@ -314,13 +321,14 @@ extension FeedBackDetailViewController: UITableViewDataSource, UITableViewDelega
textView.textColor = .black
}
if (text == "\n") {
textView.resignFirstResponder()
guard textView.text! != "" else {
guard textView.text != "发表你的看法" && textView.text! != "" else {
return true
}
textView.resignFirstResponder()
textView.endEditing(true)
FBCommentHelper.addComment(questionId: (questionOfthisPage?.id)!, contain: textView.text) { (string) in
SwiftMessages.showSuccessMessage(body: "评论发布成功!")
NotificationCenter.default.post(Notification(name: Notification.Name(FB_NOTIFICATIONFLAG_NEED_RELOAD)))
self.loadData()
textView.text = "发表你的看法"
textView.textColor = UIColor(hex6: 0xdbdbdb)
Expand Down
45 changes: 27 additions & 18 deletions WePeiYang/FeedBack/Controller/FeedBackMainViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,13 @@ let SCREEN = UIScreen.main.bounds

class FeedBackMainViewController: UIViewController {
// MARK: - UI

// 搜索框
var searchController: UISearchController!

// 问题列表
var tableView: UITableView!

// var tagCollectionView: UICollectionView!
// 标签视图
var tagSelectionView: SelectionView!

// MARK: - Data
// 可用标签
var availableTags = [
FBTagModel(id: 0, name: "教务处", children: nil),
FBTagModel(id: 0, name: "后保部", children: nil),
Expand All @@ -37,13 +35,15 @@ class FeedBackMainViewController: UIViewController {
tableView.mj_header.beginRefreshing()
}
}
// means no tag is selected
// 选择标签下标
var selectedTag: Int = -1 {
didSet {
self.tableView.mj_header.beginRefreshing()
}
}

//MARK: - DATA
var newQuestionController: FBNewQuestionViewController?
// 问题数据
var questions = [FBQuestionModel]() {
didSet {
tableView.reloadData()
Expand All @@ -52,7 +52,7 @@ class FeedBackMainViewController: UIViewController {
}
}
}

// 当前Page数
var curPage = 1 {
didSet {
if curPage != 1 {
Expand All @@ -75,7 +75,7 @@ class FeedBackMainViewController: UIViewController {
}
}
}

// CELL 注册ID
private let collectionViewCellId = "feedBackCollectionViewCellID"
private let tableViewCellId = "feedBackQuestionTableViewCellID"

Expand All @@ -85,10 +85,10 @@ class FeedBackMainViewController: UIViewController {
self.view.backgroundColor = UIColor.white
setUp()

tableView.mj_header.beginRefreshing()
loadData()

NotificationCenter.default.addObserver(self, selector: #selector(headerRefresh), name: Notification.Name(rawValue: FB_NOTIFICATIONFLAG_HAD_SEND_QUESTION), object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(loadData), name: Notification.Name(rawValue: FB_NOTIFICATIONFLAG_NEED_RELOAD), object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(reloadNewQuestionVC), name: Notification.Name(rawValue: FB_SHOULD_RELOAD_NEWQUESTIONVC), object: nil)
}

override func viewWillLayoutSubviews() {
Expand Down Expand Up @@ -228,14 +228,14 @@ extension FeedBackMainViewController: UISearchControllerDelegate {
self.navigationController?.pushViewController(vc, animated: true)
}
floaty.addItem("添加问题", icon: UIImage(named: "feedback_add_question")) { (_) in
let addVC = FBNewQuestionViewController()
addVC.availableTags = self.availableTags
self.present(addVC, animated: true, completion: nil)
if self.newQuestionController == nil {
self.newQuestionController = FBNewQuestionViewController()
self.newQuestionController?.availableTags = self.availableTags
}
self.present(self.newQuestionController!, animated: true, completion: nil)
}
view.addSubview(floaty)
}


}

// MARK: - TableView Delegate & cell
Expand Down Expand Up @@ -277,7 +277,9 @@ extension FeedBackMainViewController: UITableViewDataSource, UITableViewDelegate

// MARK: - Data Control
extension FeedBackMainViewController {
private func loadData() {
@objc private func loadData() {
tableView.mj_header.beginRefreshing()

FBTagsHelper.tagGet { (results) in
switch results {
case .success(let tags):
Expand All @@ -299,6 +301,13 @@ extension FeedBackMainViewController {
}
}
}

@objc private func reloadNewQuestionVC() {
if self.newQuestionController != nil {
self.newQuestionController = FBNewQuestionViewController()
self.newQuestionController?.availableTags = self.availableTags
}
}
}

// MARK: - Button Methods
Expand Down
3 changes: 2 additions & 1 deletion WePeiYang/FeedBack/Model/FBConsts.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import Foundation
// MARK: - 用户端基础URL
let FB_BASE_USER_URL: String = "https://areas.twt.edu.cn/api/user/"
let FB_USER_ID: Int = TwTUser.shared.feedbackID ?? 0
let FB_NOTIFICATIONFLAG_HAD_SEND_QUESTION: String = "HAD_NEW_QUESTION"
let FB_NOTIFICATIONFLAG_NEED_RELOAD: String = "FB_NOTIFICATIONFLAG_NEED_RELOAD"
let FB_SHOULD_RELOAD_NEWQUESTIONVC: String = "FB_SHOULD_RELOAD_NEWQUESTIONVC"

extension UIColor {
static var feedBackBlue: UIColor = UIColor(hex6: 0x3f54af)
Expand Down

0 comments on commit c2bbee4

Please sign in to comment.