使用来自 Parse 数据库的更新数据更新 UILabel 和 TextFields
Update UILabel and TextFields with Updated Data from Parse Database
我希望一切都好。我是 Swift 的新手。我正在为我的 2 个社交应用创意构建 shell。我已经使用 Parse 成功完成了登录、注册、注销和最少的查询。到现在为止,我一直在进步,但是我遇到了心理障碍。
我创建了一个用户配置文件 ViewController,它从数据库中查询当前用户的信息,并最初在控制器中显示结果;名字、姓氏等
我还创建了一个编辑个人资料 ViewController,使用户能够更新他们的个人资料信息和注销。到目前为止,我已经能够将更改提交到数据库,但是我很难更新 UILabel 和文本字段以显示新值。
一些额外的见解:因为我的主要观点是用户在成功 signin/registration 后被重定向到导航控制器中,这意味着导航栏是推断出来的。
请帮帮我!
这是我的 UserProfileViewController 的代码。如果我需要澄清,请告诉我。
override func viewDidLoad() {
super.viewDidLoad()
//---------------------------------------
//User Profile View - this can go between viewDidLoad and viewDidAppear functions.
//---------------------------------------
let userImageFile = PFUser.currentUser()["userProfileImage"] as PFFile
userImageFile.getDataInBackgroundWithBlock {
(imageData: NSData!, error: NSError!) -> Void in
if error == nil {
var image = UIImage(data:imageData)
self.currentUserProfilePicture.image = image
}
}
var query = PFUser.query()
query.whereKey("objectId", equalTo: PFUser.currentUser().objectId)
query.findObjectsInBackgroundWithBlock {
(objects: [AnyObject]!, error: NSError!) -> Void in
if error == nil {
let user = PFUser.currentUser()
var firstname = PFUser.currentUser()["firstName"]! as String
var lastname = PFUser.currentUser()["lastName"]! as String
var aboutMe = PFUser.currentUser()["aboutMe"]! as String
self.firstName.text = firstName
self.lastName.text = lastname
self.aboutMe.text = aboutMe
}
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
override func viewDidAppear(animated: Bool) {
}
您好,欢迎来到 swift。
您是否正在使用 prepareForSegue 在 ViewController 之间发送数据?
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "yourIdentifier" //you set the identifier in the storyboard
{
var vc = segue.destinationViewController as! YourDestinationViewController //the class of the destination view controller
vc.someValue = value
vc.otherValue = otherValue
vc.dataArray = array //here you set the values in the destination view controller
}
}
我希望一切都好。我是 Swift 的新手。我正在为我的 2 个社交应用创意构建 shell。我已经使用 Parse 成功完成了登录、注册、注销和最少的查询。到现在为止,我一直在进步,但是我遇到了心理障碍。
我创建了一个用户配置文件 ViewController,它从数据库中查询当前用户的信息,并最初在控制器中显示结果;名字、姓氏等
我还创建了一个编辑个人资料 ViewController,使用户能够更新他们的个人资料信息和注销。到目前为止,我已经能够将更改提交到数据库,但是我很难更新 UILabel 和文本字段以显示新值。
一些额外的见解:因为我的主要观点是用户在成功 signin/registration 后被重定向到导航控制器中,这意味着导航栏是推断出来的。
请帮帮我!
这是我的 UserProfileViewController 的代码。如果我需要澄清,请告诉我。
override func viewDidLoad() {
super.viewDidLoad()
//---------------------------------------
//User Profile View - this can go between viewDidLoad and viewDidAppear functions.
//---------------------------------------
let userImageFile = PFUser.currentUser()["userProfileImage"] as PFFile
userImageFile.getDataInBackgroundWithBlock {
(imageData: NSData!, error: NSError!) -> Void in
if error == nil {
var image = UIImage(data:imageData)
self.currentUserProfilePicture.image = image
}
}
var query = PFUser.query()
query.whereKey("objectId", equalTo: PFUser.currentUser().objectId)
query.findObjectsInBackgroundWithBlock {
(objects: [AnyObject]!, error: NSError!) -> Void in
if error == nil {
let user = PFUser.currentUser()
var firstname = PFUser.currentUser()["firstName"]! as String
var lastname = PFUser.currentUser()["lastName"]! as String
var aboutMe = PFUser.currentUser()["aboutMe"]! as String
self.firstName.text = firstName
self.lastName.text = lastname
self.aboutMe.text = aboutMe
}
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
override func viewDidAppear(animated: Bool) {
}
您好,欢迎来到 swift。
您是否正在使用 prepareForSegue 在 ViewController 之间发送数据?
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "yourIdentifier" //you set the identifier in the storyboard
{
var vc = segue.destinationViewController as! YourDestinationViewController //the class of the destination view controller
vc.someValue = value
vc.otherValue = otherValue
vc.dataArray = array //here you set the values in the destination view controller
}
}