I need to have a conditional Segue. The possible options are:
If link have a children link -> I should only reload the UICollectionView. If the link do not have a children link -> Go to other windows. This is my code.
override func viewDidLoad() {
super.viewDidLoad()
self.loaddata(self.url) }
func loaddata(url: String){
var loaded: Bool = false
api.remoteUrl = url + self.end_url
println(api.remoteUrl)
api.getData({data, error -> Void in
println("entro aqui")
if (data != nil){
println(data)
// Fix possible error if no "results" key
if let results = data["results"].array {
self.delete_subcategory_withoutvideos(results)
}
dispatch_async(dispatch_get_main_queue()) {
self.collectionView.reloadData()
//self.colle ctionView(<#collectionView: UICollectionView#>cellForItemAtIndexPath: <#NSIndexPath#>)
}
println("Data reloaded")
} else {
println("api.getData failed")
println(error)
}
//println(self.result_category)
loaded = true
self.collectionView.reloadData()
})
while (!loaded){}
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
let cell = sender as! UICollectionViewCell
let index = self.collectionView!.indexPathForCell(cell) // this return -> NSIndexPath?
if (self.result_category[index!.row]["children"].string != nil){
self.loaddata(self.result_category[index!.row]["children"].string!)
}else{
let vc : VideosViewController = segue.destinationViewController as! VideosViewController
vc.id_category = self.result_category[index!.row]["id"].intValue
println(vc.id_category)}
}