У меня есть кнопка обновления, которая подключается к facebookgraphAPI и загружает изображение профиля текущего пользователя. Я хочу, чтобы изображение на моем представлении обновилось, без перезагрузки viewController
. Есть ли способ сделать это? Я знаю, tableview
имеет reloadData
и refreshcontrol
, но я не использую tableview
.Как обновить изображение в Swift без перезагрузки страницы?
class ProfileViewController: UIViewController , UITextViewDelegate{
@IBOutlet weak var imageView: UIImageView!
@IBOutlet weak var nameLabel: UILabel!
@IBOutlet weak var profileTextView: UITextView!
@IBAction func updatePicture(sender: UIButton) {
// pulls in latest facebook profile info
let vc = ViewController()
vc.getFBUserInfo(PFUser.currentUser()!)
dispatch_async(dispatch_get_main_queue(), {() -> Void in
self.imageView.setNeedsDisplay()
self.loadPhoto()
})
}
override func viewDidLoad() {
super.viewDidLoad()
loadProfile()
loadPhoto()
}
func loadPhoto() {
currentUser()?.getPhoto({
image in
self.imageView.layer.masksToBounds = true
self.imageView.contentMode = .Center
self.imageView.image = image
})
}
func loadProfile() {
nameLabel.text = currentUser()?.name
// get the existing profile from DB
if let profile = PFUser.currentUser()!.objectForKey("profileText") as? String {
profileTextView.text = profile
}
profileTextView.delegate = self
}
User.swift getPhoto функция:
func getPhoto(callback:(UIImage) ->()) {
let imageFile = pfUser.objectForKey("picture") as! PFFile
imageFile.getDataInBackgroundWithBlock({
data, error in
if let data = data {
callback(UIImage(data: data)!)
}
})
}
попытку установить 'self.imageView.image = nil' первым, прежде чем изменить его на новое изображение –