我从 fbgraph api 获取并在视图中显示。
获取代码如下。
func fetchProfile(){
let parameters = ["fields":"email, name, picture.type(large)"]
FBSDKGraphRequest(graphPath: "me", parameters: parameters).startWithCompletionHandler { (connection, result, error) in
if error != nil{
print(error)
return
} else {
print(result)
self.nameLabel.text = result["name"] as? NSString as? String
self.emailAddress.text = result["email"] as? NSString as? String
if let picture = result["picture"] as? NSDictionary, data = picture["data"] as? NSDictionary, url = data["url"] as? String{
print("this is what yout fetch with \(url)")
self.imageView.sd_setImageWithURL(NSURL(string: url))
}
}
}
}
viewDidLoad 中的代码
override func viewDidLoad() {
super.viewDidLoad()
self.imageView.clipsToBounds = true
self.imageView.layer.masksToBounds = true
self.imageView.layer.cornerRadius = self.imageView.frame.height/2
self.fetchProfile()
}
每当应用程序运行并开始显示时,大约需要 1.5 秒才能显示所有内容。是否有任何方法可以缓存此数据,因此每当屏幕出现时,您不必等待 2.0 秒,因为它会自动显示为视图显示为其缓存。因为这是第一个出现的视图