浏览代码

帖子详情页面内存泄露处理完成

南鑫林 5 年之前
父节点
当前提交
e74262a37b

+ 0 - 3
RainbowPlanet/RainbowPlanet/Modules/CommunityModule/Community/View/Cell/RecommendFollow/CommunityRecommendFollowCollectionViewCell.swift

@@ -42,8 +42,6 @@ class CommunityRecommendFollowCollectionViewCell: UICollectionViewCell {
     
     //MARK: - 设置view
     private func setupViews() {
-        self.layer.borderColor = ke6e6e6Color.cgColor
-        self.layer.borderWidth = 1
         self.layer.cornerRadius = 4
         self.layer.masksToBounds = true
         self.backgroundColor = .white
@@ -118,7 +116,6 @@ class CommunityRecommendFollowCollectionViewCell: UICollectionViewCell {
         followButton.layer.borderWidth = 0.5
         followButton.rx.tap.subscribe(onNext: {
             [weak self] (data) in
-            followButton.isEnabled = false
             if let followClosure = self?.followClosure {
                 followClosure()
             }

+ 8 - 8
RainbowPlanet/RainbowPlanet/Modules/CommunityModule/Community/View/Header/CommunityFollowTableHeaderView.swift

@@ -27,14 +27,14 @@ class CommunityFollowTableHeaderView: BaseView {
             make.centerX.equalToSuperview()
         }
         infoLabel.snp_makeConstraints { (make) in
-            make.top.equalTo(iconImageView.snp_bottom).offset(20)
+            make.top.equalTo(iconImageView.snp_bottom).offset(5)
             make.left.right.equalToSuperview()
         }
         findFriendsButton.snp_makeConstraints { (make) in
-            make.top.equalTo(infoLabel.snp_bottom).offset(20)
-            make.height.equalTo(32)
-            make.right.equalTo(-98)
-            make.left.equalTo(98)
+            make.top.equalTo(infoLabel.snp_bottom).offset(15)
+            make.centerX.equalToSuperview()
+            make.height.equalTo(34)
+            make.width.equalTo(100)
         }
     }
     
@@ -58,7 +58,7 @@ class CommunityFollowTableHeaderView: BaseView {
         infoLabel.numberOfLines = 0
         let str = "去寻找感兴趣的好友吧~\n关注后,可以在这里看到对方的动态"
         let attributeString = NSMutableAttributedString(string:str)
-        attributeString.changeAllLineSpacing(5)
+        attributeString.changeAllLineSpacing(2)
         infoLabel.attributedText = attributeString
         infoLabel.textAlignment = .center
         return infoLabel
@@ -69,8 +69,8 @@ class CommunityFollowTableHeaderView: BaseView {
         findFriendsButton.setBackgroundImage(UIImage.imageWithColor(color: kThemeColor), for: UIControl.State.normal)
         findFriendsButton.setTitle("找朋友", for: UIControl.State.normal)
         findFriendsButton.setTitleColor(.white, for: UIControl.State.normal)
-        findFriendsButton.titleLabel?.font = kBoldFont16
-        findFriendsButton.cornerRadius = 16
+        findFriendsButton.titleLabel?.font = kRegularFont14
+        findFriendsButton.cornerRadius = 17
         findFriendsButton.masksToBounds = true
         findFriendsButton.rx.tap.subscribe(onNext: {
             [weak self] (data) in

+ 1 - 1
RainbowPlanet/RainbowPlanet/Modules/CommunityModule/Community/ViewController/Follow/CommunityFollowViewController.swift

@@ -246,7 +246,7 @@ extension CommunityFollowViewController {
                 if self?.communityFollowDataModels?.isEmpty ?? true {
                     self?.tableView.tableHeaderView = self?.followTableHeaderView
                 }else {
-                    self?.tableView.tableHeaderView = nil
+                    self?.tableView.tableHeaderView = UIView(frame: CGRect(x: 0, y: 0, width: kScreenWidth, height: 0.000001))
                 }
                 self?.tableView.reloadData()
                 MJRefreshManager.mjRefreshManagerPaginationNoHiddenFooter(tableView: self?.tableView, pagination: communityFollowFeedModel?.pagination)

+ 24 - 34
RainbowPlanet/RainbowPlanet/Modules/CommunityModule/CommunityRecommendDetail/Controller/CommunityRecommendController.swift

@@ -7,6 +7,7 @@
 //
 
 import UIKit
+import Kingfisher
 
 class CommunityRecommendController: BaseViewController {
     
@@ -16,6 +17,8 @@ class CommunityRecommendController: BaseViewController {
         if observe != nil {
             NotificationCenter.default.removeObserver(observe!)
         }
+        KingfisherManager.shared.cache.clearDiskCache()
+        KingfisherManager.shared.cache.clearMemoryCache()
     }
     weak var observe : NSObjectProtocol?
 
@@ -170,7 +173,7 @@ class CommunityRecommendController: BaseViewController {
         }).disposed(by: disposeBag)
         //用户昵称
         nameButton.rx.tap.subscribe(onNext: { [weak self] (data) in
-            
+
             if UserModel.isTokenNil() {
                 kAppDelegate.setLogin()
             }else {
@@ -206,7 +209,7 @@ class CommunityRecommendController: BaseViewController {
                 kAppDelegate.setLogin()
             }else {
                 self?.share()
-                
+
             }
         }).disposed(by: disposeBag)
         tableView.addHeader(withBeginRefresh: true, animation: true) {
@@ -225,15 +228,15 @@ class CommunityRecommendController: BaseViewController {
             case BottomClickType.typeComment:
                 self?.showKeyBoardCommentView(placeholder: "添加评论...")
             case BottomClickType.typeLike:
-                VirusViewModel.shared.virueRecordAddApiPraise(communityPostDetailModel: self?.communityPostDetailModel,commentView: (self?.commentView)!)
+                VirusViewModel.shared.virueRecordAddApiPraise(communityPostDetailModel: self?.communityPostDetailModel,commentView: self?.commentView)
             case BottomClickType.typeCollect:
-                VirusViewModel.shared.virueRecordAddApiCollection(communityPostDetailModel: self?.communityPostDetailModel,commentView: (self?.commentView)!)
+                VirusViewModel.shared.virueRecordAddApiCollection(communityPostDetailModel: self?.communityPostDetailModel,commentView: self?.commentView)
             }
         }
-        
+
         observe = NotificationCenter.default.addObserver(forName: NSNotification.Name("followApi"), object: nil, queue: OperationQueue.main) { [weak self] (notification) in
             let followStatusModel = notification.object as? FollowStatusModel
-            
+
             if self?.communityPostDetailModel?.uid == followStatusModel?.uid {
                 self?.communityPostDetailModel?.isFollow = followStatusModel?.isFollowStatus
                 self?.communityPostDetailTableViewHeaderView.communityPostDetailModel = self?.communityPostDetailModel
@@ -249,14 +252,14 @@ class CommunityRecommendController: BaseViewController {
                 self?.tableView.reloadData()
             }
         }
-        
+
         observe = NotificationCenter.default.addObserver(forName: NSNotification.Name("islikeApi"), object: nil, queue: OperationQueue.main) { [weak self] (notification) in
             let followStatusModel = notification.object as? FollowStatusModel
             if self?.communityPostDetailModel?.id == followStatusModel?.postId {
                 self?.communityPostDetailModel?.isDislike = followStatusModel?.isFollowStatus
                 self?.commentView.communityPostDetailModel = self?.communityPostDetailModel
             }
-            
+
             if !(self?.communityPostCommentModels.isEmpty ?? true) {
                 for communityPostDataModel in (self?.communityPostDataModels)! {
                     if communityPostDataModel.uid == followStatusModel?.uid {
@@ -266,7 +269,7 @@ class CommunityRecommendController: BaseViewController {
             }
             self?.tableView.reloadData()
         }
-        
+
         observe = NotificationCenter.default.addObserver(forName: NSNotification.Name("isCollectApi"), object: nil, queue: OperationQueue.main) { [weak self] (notification) in
             let followStatusModel = notification.object as? FollowStatusModel
             if self?.communityPostDetailModel?.id == followStatusModel?.postId {
@@ -307,7 +310,8 @@ class CommunityRecommendController: BaseViewController {
             sharedDetailTitle: kCommunityPostShareDetailTitle,
             shareCommunityViewType: ShareCommunityViewType.postDetail,
             completion: {
-            VirusViewModel.shared.forwarVirueRecordAddApi(postId: self.communityPostDetailModel?.id, postAuthorUid: "\(self.communityPostDetailModel?.uid ?? 0)", title: self.communityPostDetailModel?.title, content: self.communityPostDetailModel?.content, postType: self.communityPostDetailModel?.type, postCover: self.communityPostDetailModel?.img)
+                [weak self] in
+            VirusViewModel.shared.forwarVirueRecordAddApi(postId: self?.communityPostDetailModel?.id, postAuthorUid: "\(self?.communityPostDetailModel?.uid ?? 0)", title: self?.communityPostDetailModel?.title, content: self?.communityPostDetailModel?.content, postType: self?.communityPostDetailModel?.type, postCover: self?.communityPostDetailModel?.img)
         })
         shareCommunityView.saveCompletion = {
             [weak self] in
@@ -345,15 +349,17 @@ extension CommunityRecommendController {
     
     /// 帖子内容
     func communityPostDetailApi() {
-        SwiftMoyaNetWorkServiceCommunity.shared().communityPostDetailApi(id: id, completion: { [weak self] (communityPostDetailModel) -> (Void) in
+        SwiftMoyaNetWorkServiceCommunity.shared().communityPostDetailApi(id: id, completion: {
+            [weak self] (communityPostDetailModel) -> (Void) in
             
-            self?.tableView.snp.remakeConstraints { (make) in
+            self?.tableView.snp.remakeConstraints {[weak self] (make) in
                 make.top.equalToSuperview().offset(kNavBarTotalHeight)
                 make.left.right.equalToSuperview()
                 make.bottom.equalTo((self?.commentView.snp_top)!).offset(0)
             }
             
             DIYEmptyView.emptyNoDataActionTableView(tableView: self?.tableView, imageStr: .three, detailStr: .three, btnTitleStr: .two, btnClickBlock: {
+                [weak self] in
                 self?.tabBarController?.selectedIndex = 0
                 self?.navigationController?.popToRootViewController(animated: true)
             })
@@ -366,7 +372,7 @@ extension CommunityRecommendController {
             }else {
                 self?.followButton.isHidden = false
             }
-            CommunityFollowUserViewModel.setFollowType(followButton: (self?.followButton)!, followType: FollowType(rawValue: self?.communityPostDetailModel?.isFollow ?? 0) ?? .futureFollow)
+            CommunityFollowUserViewModel.setFollowType(followButton: self?.followButton, followType: FollowType(rawValue: self?.communityPostDetailModel?.isFollow ?? 0) ?? .futureFollow)
             self?.commentView.communityPostDetailModel = self?.communityPostDetailModel
             self?.count = self?.communityPostDetailModel?.commentCount ?? 0
             
@@ -380,29 +386,18 @@ extension CommunityRecommendController {
                 }else {
                     self?.followButton.isHidden = true
                 }
+
+                self?.communityPostDetailTableViewHeaderView.frame = CGRect(x: 0, y: 0, width: kScreenWidth, height: kScreenWidth)
+
                 if !(self?.communityPostDetailModel?.imgs?.isEmpty ?? true) {
-                    let height = getImageHeight(imgStr: (self?.communityPostDetailModel?.imgs?[0])!)
-                    let width = getImageWidth(imgStr: (self?.communityPostDetailModel?.imgs?[0])!)
-                    let scaleHeight = kScreenWidth*height/width
-                    if scaleHeight >= (500 * kScaleWidth) {
-                        self?.communityPostDetailTableViewHeaderView.frame = CGRect(x: 0, y: 0, width: kScreenWidth, height: 500 * kScaleWidth)
-                    }else {
-                        self?.communityPostDetailTableViewHeaderView.frame = CGRect(x: 0, y: 0, width: kScreenWidth, height: kScreenWidth*height/width)
-                    }
-                    self?.communityPostDetailTableViewHeaderView.tableView = self?.tableView
                     self?.tableView.tableHeaderView = self?.communityPostDetailTableViewHeaderView
-                    
                 }else {
                     if self?.communityPostDetailModel?.img != nil ||  self?.communityPostDetailModel?.img != "" {
-                        let height = getImageHeight(imgStr: (self?.communityPostDetailModel?.img)!)
-                        let width = getImageWidth(imgStr: (self?.communityPostDetailModel?.img)!)
-                        self?.communityPostDetailTableViewHeaderView.frame = CGRect(x: 0, y: 0, width: kScreenWidth, height: kScreenWidth*height/width)
-                        self?.communityPostDetailTableViewHeaderView.tableView = self?.tableView
                         self?.tableView.tableHeaderView = self?.communityPostDetailTableViewHeaderView
                     }
                 }
-                self?.communityPostDetailTableViewHeaderView.communityPostDetailModel = self?.communityPostDetailModel
                 
+                self?.communityPostDetailTableViewHeaderView.communityPostDetailModel = self?.communityPostDetailModel
             }
             self?.setupLayouts()
             self?.tableView.reloadData()
@@ -665,12 +660,7 @@ extension CommunityRecommendController: UITableViewDataSource, UITableViewDelega
     func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
         switch indexPath.section {
         case 0:
-            
-            if PostType(rawValue: communityPostDetailModel?.type ?? "html") == .html {
-                
-            }else {
-
-            }
+            break
         case 1:
             if communityPostCommentModels.isEmpty {
                 break

+ 6 - 52
RainbowPlanet/RainbowPlanet/Modules/CommunityModule/CommunityRecommendDetail/View/CommunityPostDetailTableViewHeaderView.swift

@@ -12,6 +12,10 @@ import SwiftyMediator
 
 class CommunityPostDetailTableViewHeaderView: BaseView {
     
+    deinit {
+        NXLLog("deinit")
+    }
+    
     override func setupViews() {
          addSubview(pagerView)
          addSubview(numberLabel)
@@ -29,13 +33,12 @@ class CommunityPostDetailTableViewHeaderView: BaseView {
     }
     
     private lazy var pagerView: FSPagerView = {
-        [unowned self] in
         let pagerView = FSPagerView(frame: CGRect.zero)
         pagerView.backgroundColor = kf7f8faColor
-        pagerView.delegate = self
-        pagerView.dataSource = self
         pagerView.scrollDirection = .horizontal
         pagerView.bounces = false
+        pagerView.delegate = self
+        pagerView.dataSource = self
         return pagerView
     }()
     
@@ -70,10 +73,7 @@ class CommunityPostDetailTableViewHeaderView: BaseView {
     }
     
     var imgs = Array<String>()
-    var height1 = 0.0
     
-    var tableView:UITableView?
-
 }
 
 extension CommunityPostDetailTableViewHeaderView:FSPagerViewDataSource,FSPagerViewDelegate {
@@ -82,14 +82,6 @@ extension CommunityPostDetailTableViewHeaderView:FSPagerViewDataSource,FSPagerVi
     }
     func pagerView(_ pagerView: FSPagerView, cellForItemAt index: Int) -> FSPagerViewCell {
         let cell  = CommunityPostDetailFSPagerViewCell.cellWith(collectionView: pagerView, index: index)
-        let height = getImageHeight(imgStr: imgs[index])
-        let width = getImageWidth(imgStr: imgs[index])
-        let scaleHeight = kScreenWidth*height/width
-        if scaleHeight >= (500 * kScaleWidth) {
-            cell.size = CGSize(width: kScreenWidth, height: 500 * kScaleWidth)
-        }else {
-            cell.size = CGSize(width: kScreenWidth, height: kScreenWidth*height/width)
-        }
         cell.img = imgs[index]
         return cell
     }
@@ -99,50 +91,12 @@ extension CommunityPostDetailTableViewHeaderView:FSPagerViewDataSource,FSPagerVi
         Mediator.push(BrowsePictureRouterModuleType.pushBrowsePictureImageStrs(imageStrs: imgs, index: index))
         
     }
-    
-    func pagerViewWillBeginDragging(_ pagerView: FSPagerView) {
-        let currentIndex = pagerView.currentIndex
-        let cell = pagerView.cellForItem(at: currentIndex) as! CommunityPostDetailFSPagerViewCell
-        UIView.animate(withDuration: 0.5) {
-            [weak self] in
-            self?.size = cell.size
-            self?.tableView?.reloadData()
-        }
-    }
     func pagerViewWillEndDragging(_ pagerView: FSPagerView, targetIndex: Int) {
-        let currentIndex = pagerView.currentIndex
         self.numberLabel.text =  "  \(targetIndex+1)/" + "\(imgs.count)  "
-        let cell = pagerView.cellForItem(at: currentIndex) as! CommunityPostDetailFSPagerViewCell
-        UIView.animate(withDuration: 0.5) {
-            [weak self] in
-            self?.size = cell.size
-            self?.tableView?.reloadData()
-        }
     }
     func pagerViewDidScroll(_ pagerView: FSPagerView) {
     }
     
-    func pagerView(_ pagerView: FSPagerView, willDisplay cell: FSPagerViewCell, forItemAt index: Int) {
-        //        UIView.animate(withDuration: 0.2) {
-        //            self.size = cell.size
-        //            self.tableView?.reloadData()
-        //        }
-    }
-
-    func pagerView(_ pagerView: FSPagerView, didEndDisplaying cell: FSPagerViewCell, forItemAt index: Int) {
-        let currentIndex = pagerView.currentIndex
-        let cell = pagerView.cellForItem(at: currentIndex) as! CommunityPostDetailFSPagerViewCell
-        UIView.animate(withDuration: 0.5) {
-            [weak self] in
-            self?.size = cell.size
-            self?.tableView?.reloadData()
-        }
-    }
-    
-    func pagerViewDidEndDecelerating(_ pagerView: FSPagerView) {
-        
-    }
-    
 }
 
 

+ 4 - 0
RainbowPlanet/RainbowPlanet/Modules/CommunityModule/CommunityRecommendDetail/View/RecommendBottomCommentView.swift

@@ -18,6 +18,10 @@ enum BottomClickType {
 
 class RecommendBottomCommentView: BaseView {
     
+    deinit {
+        NXLLog("deinit")
+    }
+    
     typealias BottomClickClosure = (_ clickType: BottomClickType) -> Void
     var bottomClickClosure : BottomClickClosure?
     

+ 15 - 11
RainbowPlanet/RainbowPlanet/Modules/CommunityModule/CommunityRecommendDetail/View/RecommendSimilarCell.swift

@@ -10,6 +10,11 @@ import UIKit
 
 class RecommendSimilarCell: UITableViewCell {
     
+    deinit {
+        NXLLog("deinit")
+
+    }
+    
     class func cellWith(tableView:UITableView,indexPath:IndexPath) -> RecommendSimilarCell {
         let ID = "RecommendSimilarCell"
         tableView.register(RecommendSimilarCell.self, forCellReuseIdentifier: ID)
@@ -39,6 +44,7 @@ class RecommendSimilarCell: UITableViewCell {
         self.selectionStyle = .none
         backgroundColor = kf7f8faColor
         addSubview(collectionView)
+
     }
     
     private func setupLayouts() {
@@ -60,10 +66,10 @@ class RecommendSimilarCell: UITableViewCell {
         collectionView.showsHorizontalScrollIndicator = false
         collectionView.bounces = false
         collectionView.isScrollEnabled = false
+
         return collectionView
     }()
     private lazy var collectionViewLayout: WaterFallLayout = {
-        [unowned self] in
         let collectionViewLayout = WaterFallLayout()
         collectionViewLayout.delegate = self
         collectionViewLayout.scrollDirection = .horizontal
@@ -131,20 +137,19 @@ extension RecommendSimilarCell: UICollectionViewDelegateFlowLayout,UICollectionV
     
     func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
         return communityPostDataModels?.isEmpty ?? true ? 0 : communityPostDataModels?.count ?? 0
-        
     }
     
     func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
         let cell = SearchContentListCollectionCell.cellWith(collectionView: collectionView, indexPath: indexPath)
         cell.communityPostDataModel = communityPostDataModels?[indexPath.row]
-        cell.userClosure = {
-            [weak self] in
-            if cell.communityPostDataModel?.uid != UserModel.shared().getModel()?.uid {
-                let vc = OtherPersonalCenterViewController()
-                vc.uid = cell.communityPostDataModel?.uid ?? 0
-                self?.findViewController().navigationController?.pushViewController(vc, animated: true)
-            }
-        }
+//        cell.userClosure = {
+//            [weak self] in
+//            if cell.communityPostDataModel?.uid != UserModel.shared().getModel()?.uid {
+//                let vc = OtherPersonalCenterViewController()
+//                vc.uid = cell.communityPostDataModel?.uid ?? 0
+//                self?.findViewController().navigationController?.pushViewController(vc, animated: true)
+//            }
+//        }
         return cell
     }
     
@@ -161,7 +166,6 @@ extension RecommendSimilarCell: UICollectionViewDelegateFlowLayout,UICollectionV
              findViewController().navigationController?.pushViewController(vc, animated: true)
         }
         
-        
     }
     
 }

+ 4 - 1
RainbowPlanet/RainbowPlanet/Modules/SearchModule/SearchContentList/View/SearchContentListCollectionCell.swift

@@ -11,6 +11,9 @@ import RxSwift
 import Lottie
 
 class SearchContentListCollectionCell: UICollectionViewCell {
+    deinit {
+        NXLLog("deinit")
+    }
     
     let disposeBag = DisposeBag()
     
@@ -175,7 +178,7 @@ class SearchContentListCollectionCell: UICollectionViewCell {
             }else {
                 if self?.communityPostDataModel?.isLike == 0 {
                     self?.praiseAnimationView.isHidden = false
-                    self?.praiseAnimationView.play(completion: { (_) in
+                    self?.praiseAnimationView.play(completion: { [weak self] (_) in
                         self?.praiseAnimationView.isHidden = true
                     })
                 }

+ 1 - 1
RainbowPlanet/RainbowPlanet/Tools/WaterFallLayout/WaterFallLayout.h

@@ -38,6 +38,6 @@
 
 @interface WaterFallLayout : UICollectionViewFlowLayout
 
-@property (nonatomic) id<WaterFallLayoutDelegate> delegate;
+@property (nonatomic,weak) id<WaterFallLayoutDelegate> delegate;
 
 @end