ios uiview 如何刷新_ios-如何在Swift中刷新imageview而无需重新加载页面?

我有一个更新照片按钮,该按钮连接到facebookgraphAPI并下载当前用户的个人资料图片.

我希望刷新视图上的图像,而无需重新加载viewController.

有什么办法可以做到这一点?我知道tableview具有reloadData和refreshcontrol,但是我没有使用tableview.

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)!)

}

})

}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值