iOS:UI(UIButtons)在使用.getDataInBackgroundWithBlock后损坏
在我的故事板中,我有一个嵌入在NavigationController中的ViewController,它带有UI按钮和可拖动/可单击的UI视图。可拖动视图从parse.com获取。在我的纯文本版本中,一切正常:iOS:UI(UIButtons)在使用.getDataInBackgroundWithBlock后损坏,ios,user-interface,swift,parse-platform,Ios,User Interface,Swift,Parse Platform,在我的故事板中,我有一个嵌入在NavigationController中的ViewController,它带有UI按钮和可拖动/可单击的UI视图。可拖动视图从parse.com获取。在我的纯文本版本中,一切正常: query!.findObjectsInBackgroundWithBlock { (objects: [AnyObject]?, error: NSError?) -> Void in if error != nil {
query!.findObjectsInBackgroundWithBlock {
(objects: [AnyObject]?, error: NSError?) -> Void in
if error != nil {
println("DB Error: \(error)")
} else {
// Get data
let fetchProducts:[Product] = objects as! [Product]
self.products = fetchProducts
self.loadCards()
}
}
然后我扩展了这段代码,使其能够从parse.com获取图像。我可以看到图像,但我的按钮不再可点击。NavigationController中的BarButtonItem可以工作,甚至DragTableView也可以移动和单击。我真不明白为什么钮扣坏了。在我的扩展代码中,我没有看到任何相关的UIButton代码会影响以下内容:
query!.findObjectsInBackgroundWithBlock {
(objects: [AnyObject]?, error: NSError?) -> Void in
if error != nil {
println("DB Error: \(error)")
} else {
// Get data
let fetchProducts:[Product] = objects as! [Product]
// TODO: Fetching Images!!!
let maxFetch = fetchProducts.count
var maxFetchCounter = 0
for fetchProduct in fetchProducts {
let userImageFile = fetchProduct.image as PFFile
userImageFile.getDataInBackgroundWithBlock {
(imageData: NSData?, error: NSError?) -> Void in
if error == nil {
maxFetchCounter++
if let imageData = imageData {
let image = UIImage(data:imageData)
fetchProduct.productImage = image
self.products.append(fetchProduct)
}
if maxFetchCounter == maxFetch {
self.loadCards()
}
}
}
}
}
}
我已经为这个问题挣扎了两天。我希望有人能帮忙。提前谢谢
[编辑:4月21日]
我发现了另一件奇怪的事情——如果我在一个额外的函数中排除了代码,那么UIButton又开始工作了。但是如果我经常在短时间内启动函数,并不是所有的图像都会出现
query!.findObjectsInBackgroundWithBlock {
(objects: [AnyObject]?, error: NSError?) -> Void in
if error != nil {
println("DB Error: \(error)")
} else {
// Get data
let fetchProducts:[Product] = objects as! [Product]
self.products = fetchProducts
self.updateImageFromParse()
}
}
和ne功能
func updateImageFromParse() {
let maxFetch = self.products.count
var maxFetchCounter = 0
println("Get Images")
for fetchProduct in self.products {
let userImageFile = fetchProduct.image as PFFile
userImageFile.getDataInBackgroundWithBlock {
(imageData: NSData?, error: NSError?) -> Void in
if error == nil {
maxFetchCounter++
println("Count: \(maxFetchCounter)/\(maxFetch)")
if let imageData = imageData {
let image = UIImage(data:imageData)
fetchProduct.productImage = image
} else {
println("ERROR: NO PICTURE !!!!!")
}
if maxFetchCounter == maxFetch {
self.loadCards()
}
}
}
}
}
如果我排除函数中的代码,我甚至不知道UIButtons为什么会工作://在这段代码中,我看不到对导航控制器的引用,所以我很困惑……代码只是我整个ViewController的一部分。这与这个片段无关。我提到这件事是因为巴布顿人在工作。。。在我添加图像抓取后,只有VC视图中的UIButton不可单击:这些查询抓取发生在哪里?这些是在viewDidLoad中发生的吗?