From b9df444cf4a58d01320f13e65b2814ba8cd612f6 Mon Sep 17 00:00:00 2001 From: ylzheng Date: Sun, 15 Nov 2015 22:04:14 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=B8=80=E8=87=B4=E6=80=A7?= =?UTF-8?q?=E4=BD=93=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- librx/Base.lproj/Main.storyboard | 4 ++-- librx/ExploreCollectionReusableView.swift | 11 ++++++--- librx/ExploreTableViewController.swift | 7 ++++++ librx/LibrxService.swift | 16 ++++++++----- librx/ProfileViewController.swift | 12 +++++++--- librx/StorysTableViewController.swift | 28 ++++++++++++++--------- librx/WebViewController.swift | 5 +++- 7 files changed, 57 insertions(+), 26 deletions(-) diff --git a/librx/Base.lproj/Main.storyboard b/librx/Base.lproj/Main.storyboard index 33a4c89..cf19ea3 100644 --- a/librx/Base.lproj/Main.storyboard +++ b/librx/Base.lproj/Main.storyboard @@ -819,7 +819,7 @@ - + @@ -1691,7 +1691,7 @@ - + diff --git a/librx/ExploreCollectionReusableView.swift b/librx/ExploreCollectionReusableView.swift index db89a47..0bcc134 100644 --- a/librx/ExploreCollectionReusableView.swift +++ b/librx/ExploreCollectionReusableView.swift @@ -27,9 +27,7 @@ class ExploreCollectionViewController: UICollectionViewController, UICollectionV override func viewDidLoad() { super.viewDidLoad() - self.navigationController?.navigationBar.tintColor = UIColor.whiteColor() - self.navigationController?.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName: UIColor.whiteColor()] screenSize = UIScreen.mainScreen().bounds @@ -41,14 +39,21 @@ class ExploreCollectionViewController: UICollectionViewController, UICollectionV override func viewDidAppear(animated: Bool) { super.viewDidAppear(animated) + + self.navigationController?.navigationBarHidden = false + self.navigationController?.setNavigationBarHidden(false, animated: false) + LibrxService.loadExplore { (explores) -> () in self.explores = explores self.collectionView?.reloadData() } - } + override func prefersStatusBarHidden() -> Bool { + return false + } + override func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int { return 1 } diff --git a/librx/ExploreTableViewController.swift b/librx/ExploreTableViewController.swift index 385a69e..d8608cb 100644 --- a/librx/ExploreTableViewController.swift +++ b/librx/ExploreTableViewController.swift @@ -26,11 +26,18 @@ class ExploreTableViewController: UITableViewController { override func viewDidAppear(animated: Bool) { super.viewDidAppear(animated) + self.navigationController?.navigationBarHidden = false + self.navigationController?.setNavigationBarHidden(false, animated: true) + refreshContent() self.tableView.reloadData() } + override func prefersStatusBarHidden() -> Bool { + return false + } + func refreshContent() { loadPostsFromUrl(self.dataUrl!) self.tableView.reloadData() diff --git a/librx/LibrxService.swift b/librx/LibrxService.swift index 2134a0d..5350b39 100644 --- a/librx/LibrxService.swift +++ b/librx/LibrxService.swift @@ -15,7 +15,7 @@ import JWT struct LibrxService { - private static let baseURL = "http://123.57.95.237" + private static let baseURL = "http://uat.librme.com" private static let defaultThumail = "http://7pn5d3.com1.z0.glb.clouddn.com/9050353.png" @@ -179,6 +179,8 @@ struct LibrxService { Alamofire.request(.GET, urlString, headers: headers) .response{ (request, res, data, error) in + print(urlString) + var posts:[Post] = [] if let _ = error{ return response(posts, error: "Libr失联了,请稍候再试...") @@ -186,10 +188,13 @@ struct LibrxService { LocalStore.setLocalCachePosts(data!) let json = JSON(data: data!) - for index in 0.. Void in} } diff --git a/librx/ProfileViewController.swift b/librx/ProfileViewController.swift index 0a46b92..dd90912 100644 --- a/librx/ProfileViewController.swift +++ b/librx/ProfileViewController.swift @@ -55,10 +55,12 @@ class ProfileViewController: UIViewController{ self.followButton.layer.borderColor = UIColor.whiteColor().CGColor self.followButton.hidden = true - navigationController?.navigationBar.backgroundColor = UIColor.whiteColor() - navigationController?.navigationBar.tintColor = UIColor.whiteColor() + self.navigationController?.navigationBar.backgroundColor = UIColor.whiteColor() + self.navigationController?.navigationBar.tintColor = UIColor.whiteColor() + + self.navigationController?.navigationBarHidden = false + self.navigationController?.setNavigationBarHidden(false, animated: true) - navigationController?.navigationBar.backItem?.hidesBackButton = false self.settingButton.hidden = true self.backButton.hidden = true @@ -80,6 +82,10 @@ class ProfileViewController: UIViewController{ } + override func prefersStatusBarHidden() -> Bool { + return false + } + func loadUserProfile(userId: Int){ LibrxService.profile(userId) { [weak self](profile) -> () in diff --git a/librx/StorysTableViewController.swift b/librx/StorysTableViewController.swift index 37662dc..980d4c4 100644 --- a/librx/StorysTableViewController.swift +++ b/librx/StorysTableViewController.swift @@ -156,10 +156,12 @@ class StorysTableViewController: UITableViewController { func refresh() { print("refreshing...") - postsLoader.load(completion: { [unowned self] (posts, error) in - self.posts = posts - self.tableView.reloadData() - self.refreshControl?.endRefreshing() + postsLoader.load(completion: { [weak self] (posts, error) in + if let selfView = self { + selfView.posts = posts + selfView.tableView.reloadData() + selfView.refreshControl?.endRefreshing() + } }) timer = NSTimer.scheduledTimerWithTimeInterval(3.0, target: self, selector: "endOfWork", userInfo: nil, repeats: true) } @@ -178,13 +180,17 @@ class StorysTableViewController: UITableViewController { func loadMore() { print("load more data") - postsLoader.load(currentPage+1, completion: { [unowned self] (posts, error) in - if posts.count == 0 { - print("没有数据了") - } else{ - self.posts += posts - self.currentPage += 1 - self.tableView.reloadData() + postsLoader.load(currentPage+1, completion: { [weak self] (posts, error) in + + if let selfView = self { + + if posts.count == 0 { + print("没有数据了") + } else{ + selfView.posts += posts + selfView.currentPage += 1 + selfView.tableView.reloadData() + } } }) } diff --git a/librx/WebViewController.swift b/librx/WebViewController.swift index bb220f4..710ab22 100644 --- a/librx/WebViewController.swift +++ b/librx/WebViewController.swift @@ -104,7 +104,10 @@ class WebViewController: UIViewController { } @IBAction func dismiss(sender: AnyObject) { - self.navigationController?.popViewControllerAnimated(true) + if let _ = self.navigationController { + self.navigationController?.popViewControllerAnimated(true) + return + } self.dismissViewControllerAnimated(true, completion: nil) }