diff --git a/librx/Base.lproj/Main.storyboard b/librx/Base.lproj/Main.storyboard index 2266ef2..d95ce37 100644 --- a/librx/Base.lproj/Main.storyboard +++ b/librx/Base.lproj/Main.storyboard @@ -1151,7 +1151,6 @@ - @@ -1681,7 +1680,7 @@ - + diff --git a/librx/LibrxService.swift b/librx/LibrxService.swift index 1c5ae6a..29c754a 100644 --- a/librx/LibrxService.swift +++ b/librx/LibrxService.swift @@ -179,8 +179,6 @@ 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失联了,请稍候再试...") @@ -188,7 +186,8 @@ struct LibrxService { LocalStore.setLocalCachePosts(data!) let json = JSON(data: data!) - if !json.isEmpty { + + if json != nil { for index in 0.. ()) { + static func profile(userId: Int, response: (Profile?) -> ()) { let urlString = baseURL + ResourcePath.User(userId: userId).description let headers:[String: String] = buildHttpRequestHeader() @@ -391,8 +390,17 @@ struct LibrxService { (_,_,data,error) in let json = JSON(data: data!) - let profile = JsonPaser.parseProfile(json) - response(profile) + + if let _ = error { + response(nil) + } else { + if json != nil { + let profile = JsonPaser.parseProfile(json) + response(profile) + } else { + response(nil) + } + } } @@ -428,8 +436,12 @@ struct LibrxService { if let _ = error { response(nil) } else { - let profile = JsonPaser.parseProfile(json) - response(profile) + if json != nil { + let profile = JsonPaser.parseProfile(json) + response(profile) + } else { + response(nil) + } } diff --git a/librx/ProfileViewController.swift b/librx/ProfileViewController.swift index dd90912..3818b1f 100644 --- a/librx/ProfileViewController.swift +++ b/librx/ProfileViewController.swift @@ -91,26 +91,28 @@ class ProfileViewController: UIViewController{ LibrxService.profile(userId) { [weak self](profile) -> () in if let selfView = self { - let avatar = NSURL(string: profile.avatar) - selfView.avatarImageView.sd_setImageWithURL(avatar, placeholderImage: UIImage(named: "default")) - selfView.nameLabel.text = profile.name - selfView.subTitleLabel.text = "简介:\(profile.email)" - selfView.followerNumLabel.text = String(profile.followersCount) - selfView.follosNumLabel.text = String(profile.followsCount) - if let loginEdUserId = LocalStore.accessUserId() { + if let thatProfile = profile { + let avatar = NSURL(string: thatProfile.avatar) + selfView.avatarImageView.sd_setImageWithURL(avatar, placeholderImage: UIImage(named: "default")) + selfView.nameLabel.text = thatProfile.name + selfView.subTitleLabel.text = "简介:\(thatProfile.email)" + selfView.followerNumLabel.text = String(thatProfile.followersCount) + selfView.follosNumLabel.text = String(thatProfile.followsCount) + if let loginEdUserId = LocalStore.accessUserId() { - if selfView.userId != loginEdUserId { + if selfView.userId != loginEdUserId { - selfView.isFollowed = profile.followed - if profile.followed { - selfView.followButton.setTitle("已关注", forState: .Normal) - } else { - selfView.followButton.setTitle("关注", forState: .Normal) - } - selfView.followButton.hidden = false + selfView.isFollowed = thatProfile.followed + if thatProfile.followed { + selfView.followButton.setTitle("已关注", forState: .Normal) + } else { + selfView.followButton.setTitle("关注", forState: .Normal) + } + selfView.followButton.hidden = false } } + } }