I have three different arrays that hold information. One displays the section title, one displays the title of each cell, and one provides a link to the other viewController. I am using Swift btw.
But when I run it, all the cells use the first url in the array and not the rest of the url's.
Here is my code:
import UIKit
class FirstViewController: UIViewController, UITableViewDataSource,
UITableViewDelegate {
var headers = ["Bein Sports", "Sky Sports", "Alkass"]
var channels = [["Bein Sports 1","Bein Sports 2","Bein Sports 3","Bein Sports 4","Bein Sports 5","Bein Sports 6","Bein Sports 7","Bein Sports 8","Bein Sports 9","Bein Sports 10","Bein Sports News"],
["Sky Sports 1","Sky Sports 2","Sky Sports 3","Sky Sports 4","Sky Sports 5"], ["Alkass One", "Alkass Two", "Alkass Three", "Alkass Four", "Alkass Five"]]
var links = ["https://google.ca","https://facebook.com","https://facebook.com","https://facebook.com","https://facebook.com","https://facebook.com","https://facebook.com","https://facebook.com","https://facebook.com","https://facebook.com","https://facebook.com","https://facebook.com","https://facebook.com","https://facebook.com","https://facebook.com","https://facebook.com","https://facebook.com","https://facebook.com","https://facebook.com","https://facebook.com","https://facebook.com"]
var myIndex: IndexPath?
func numberOfSections(in tableView: UITableView) -> Int {
return headers.count
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return channels[section].count
}
func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
return headers[section]
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
cell.textLabel?.text = channels[indexPath.section][indexPath.row]
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
myIndex = indexPath
performSegue(withIdentifier: "segue", sender: self)
}
}