I have an array of strings in which I store strings, that later I add to the URL for the .GET request on Alamofire. I use a for loop to iterate through the array so for each element Alamofire would make a .GET request and receive a JSON that after being parse I will append to another string.
The fact is that I have a CollectionView inside a TableViewCell, what I do is create a cell for each of the elements in the forenamed array, and a row of CollectionView with the content that I get from the .GET request the problem is that the name of the TableViewCell DOES NOT match the content appearing on the CollectionView.
This is the code that I am using at the moment:
func downloadRadios(){
for names in browse{
index.append(names)
let url = "http://api.dirble.com/v2/search/\(names)?token="
Alamofire.request(.GET, url).validate().responseJSON { response in
switch response.result {
case .Success(let data):
let json = JSON(data)
if let arr = json.arrayObject as? [[String:AnyObject]] {
var myRadio = [String]()
for items in arr{
let name = items["name"] as? String
myRadio.append(name!)
}
print(myRadio)
self.radio.append(myRadio)
self.tableView.reloadData()
}
case .Failure(let error):
print("Request failed with error: \(error)")
}
}
}
print("radio vale\(radio.count)")
}
Code to populate the TableView:
func tableView(tableView: UITableView,
cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("PopularRadioTableViewCell", forIndexPath: indexPath) as! PopularRadioTableViewCell
cell.configureCell(index[indexPath.row])
return cell
}
Code to populate the CollectionView:
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("PopularRadioCell", forIndexPath: indexPath) as! PopularRadioCell
cell.configureCell(radio[collectionView.tag][indexPath.item], image:"hey")
return cell
}