我有一个应该按如下方式工作的函数:
如果错误,可以正常工作并继续进行“网络化”工作。功能下载视频。
如果是,则仅显示以前的下载,但不会为新视频建立网络。有人可以发现任何错误吗?
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
selectedID = defaults.arrayForKey("playlistID")![indexPath.row] as! String
playlistThumb = defaults.arrayForKey("playlistThumbnails")![indexPath.row] as! NSData
if defaults.boolForKey("\(self.selectedID)gotSub") {
ActionSheetStringPicker.showPickerWithTitle("Elige una Subcategoria",
rows: defaults.arrayForKey("\(selectedID)subArray"),
initialSelection: 0, doneBlock: {
picker, values, indexes in
self.selectedSub = self.catArray[values]
self.performSegueWithIdentifier("to_vid", sender: self)
return
},
cancelBlock: {
ActionStringCancelBlock in
return
}, origin: self.tableView(mainTbl, cellForRowAtIndexPath: indexPath))
} else {
animator.hidden = false
animator.startAnimating()
}
Networking().getVideos(selectedID) { (result: String) -> () in
self.animator.stopAnimating()
self.animator.hidden = true
defaults.removeObjectForKey("\(self.selectedID)subArray")
defaults.removeObjectForKey("\(self.selectedID)catArray")
defaults.setBool(false, forKey: "\(self.selectedID)gotSub")
self.subArray = []
self.catArray = []
let array = defaults.arrayForKey("\(self.selectedID)videoTitles") as! [String]
for i in 0..<array.count {
let categoryCode = Parser().getCategory(array[i])
if !self.catArray.contains(categoryCode) {
self.catArray.append(categoryCode)
let categoryTitle = Parser().getCat(array[i])
self.subArray.append(categoryTitle)
}
}
if defaults.boolForKey("\(self.selectedID)gotSub") {
self.actionBool = true
}
defaults.setBool(true, forKey: "\(self.selectedID)gotSub")
defaults.setObject(self.subArray, forKey: "\(self.selectedID)subArray")
defaults.setObject(self.catArray, forKey: "\(self.selectedID)catArray")
if !self.actionBool {
self.mainTbl.selectRowAtIndexPath(indexPath, animated: false, scrollPosition: UITableViewScrollPosition.None)
self.tableView(self.mainTbl, didSelectRowAtIndexPath: indexPath)
}
}
}