- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在这件事上浪费了太多时间。也许这就是为什么我看不到问题所在。
我正在将 PFUser 数据从 Parse 加载到 View 中,以便可以对其进行编辑等。
在解包一个我知道有值的可选值时,我的代码的这一部分不断崩溃,意外发现 nil。
func loadUser() {
// var currentUser = PFUser.currentUser()
println(currentUser)
//currentUser = nil
if currentUser != nil {
if let userImageView = currentUser?["picture"] as? PFFile {
userImageView.getDataInBackgroundWithBlock {(imageData: NSData?, error: NSError?) -> Void in
if error == nil {
if let imageData = imageData {
let image = UIImage(data:imageData)
}
}
}
}
if let currentUser = currentUser {
var userName: AnyObject? = currentUser["username"]
println(userName)
// if let currentUser = currentUser {
self.nameField.text = userName as! String
// }
}
}
}
println(currentUser) 和 println(userName) 都有值并显示在我的控制台上。
最佳答案
虽然看起来不太可能,但您的 currentUser
变量可能会从您脚下被释放 - 为什么不从一开始就使用条件赋值:
if let currentUser = currentUser {
if let userImageView = currentUser["picture"] as? PFFile {
userImageView.getDataInBackgroundWithBlock { (imageData: NSData?, error: NSError?) -> Void in
if error == nil {
if let imageData = imageData {
if let image = UIImage(data:imageData) {
// do whatever you want to do with your image
}
}
}
}
}
if let userName: String = currentUser["username"] as? String {
println(userName)
self.nameField.text = userName
}
}
鉴于您所说的崩溃位置,您的 currentUser
对象似乎更有可能具有 nil
userName
属性(或一个这不是一个字符串
。
此外,UIImage(data: NSData)
返回一个可选值,因此如果您尝试使用它,它可能是nil
(并且,具体取决于您所使用的库)使用时,它可能被声明为隐式解包的可选)。
由于这些类型的错误,我通常会避免像瘟疫这样的隐式解包选项 - 如果您始终使用条件赋值而不是检查 nil,然后尝试使用该变量作为隐式解包选项,那么这种情况就不会发生。
关于ios - 在展开可选内容时,将 Parse PFUser 信息快速加载到 View 中失败,并发现 nil,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32336475/
我有两个数组,arrayA 和 arrayB,它们都具有相同的元素,其中都是 PFUsers。虽然arrayB的顺序错了,需要按照arrayA的顺序。谁能告诉我一些能够做到这一点的代码? 最佳答案 您
我正在创建一个新的 PFUser 作为当前登录用户的“子用户”。 例如,Master 登录并决定创建一个 Junior User。 Junior 用户将拥有与 Master 不同的 PFRole。 我
我一整天都在想我做错了什么,但我完全不知道为什么应用程序总是崩溃。 情况如下: 我已经建立了一个简单的项目,其中实现了所有必需的库和框架。我使用以下实例方法创建了几个 Parse Users: [se
所以在我的应用程序中,我对用户帐户使用 Parse。我有一个“关注”类,其中包含包含用户对象 ID 的“至”和“来自”字段,允许用户相互关注。现在,如果我以某种方式删除用户,跟随关系将保持不变,并且查
对于一个很长的问题,我深表歉意。大部分代码都是多余的。请看一下!!! 起初,我认为指定的信息是在 else 部分发送的,正如 Parse 文档所示,https://parse.com/docs/ios
我有一个从 Parse 为我的 PFUser 构建的模型: import Foundation import Parse class TradeUser : PFUser { override cla
我正在使用: } else if segue.identifier == "logout" { var currentUser = PFUser.currentUser() PFUse
我有一个文本字段,用户可以在其中输入另一个用户的用户名,将他添加为 friend 。我使用 PFQuery 查询所有用户,然后检查在文本字段中输入的用户名是否存在。如果存在,则会出现一个按钮(我知道我
我尝试使用以下代码将对象添加到 PFUser: @IBAction func ButtonPressed(sender: AnyObject) { var user = PFUser.curr
如何让用户更改密码、邮件、用户名等。有什么想法吗?到目前为止,我有这段代码,您可以在下面看到。我的问题是旧数据没有显示,我无法更新它。我会喜欢一些帮助! :) 非常感谢 #import #impor
我有一个 PFUser 在两台 iOS 设备上登录。当每个应用程序启动时,我需要从服务器下载 PFUser 数据以保留最新数据(在第二个设备上制作)。 有什么方法可以做到这一点吗?因为在文档中没有提到
我正在尝试在我的 ios9 项目上进行跟随解析操作,但在从中检索 PFUser 时遇到了一些问题解析使用 objectId 任何人都可以帮助我(问题是将当前用户的用户 ID 添加到后面的用户) - (
我正在尝试像这样对 PFUser 进行子类化: // User.h #import @interface User : PFUser @property (nonatomic, copy) NS
我正在为后端使用 Parse,并且正在设计 Activity 类。事件类有 4 列。 fromUser(那将是 PFUser currentUser),activityType(字符串:假设它是“li
关闭。这个问题需要更多focused .它目前不接受答案。 想改进这个问题吗? 更新问题,使其只关注一个问题 editing this post . 关闭 5 年前。 Improve this qu
我试图找出如何找到具有约束的 PFUser,这是我找到的唯一方法。我不知道我是否做错了,但是您将如何显示结果?当我尝试用 println(query) 显示结果时,它返回被方括号包围的 PFQuery
我正在尝试使用 Javascript Parse SDK 编写一个云函数,我想知道是否可以为不同的用户重新保存行键。到目前为止,我已经得到它来查询我想要的用户,现在我只是尝试将这些用户的“maxAwa
我想让我的用户能够删除其帐户,从而不会出现在其他用户的供稿中。 我可以这样做的一种方法是在“用户”表中添加“ Activity ”列。 更好的方法是从表中删除其User对象。不幸的是,当我执行此操作时
序言 我使用 Parse.com 作为后端。 我已经建立了注册和身份验证功能来证实 PFUser。 我已经建立了一个注销按钮来将 PFUser 值重置为 0(零)。 这些功能存在于独立于应用程序核心的
我开发了一个 friend 关系应用程序,用户可以将现有用户添加为 friend 。然后我正在做一个搜索好友功能,我的表结构如下:PFUser --> 记录当前用户(标准类)FriendList --
我是一名优秀的程序员,十分优秀!