Reputation: 33
When I take var type variable then Xcode show warning
variable is never mutated
If I take let type variable then don't show any result!
import UIKit
class ViewController: UIViewController,UITableViewDataSource{
let people = [
("Pankaj","Dhaka"),
("Asish","Madaripur"),
("Anup","Narail")
]
func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
return "People"
}
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return people.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = UITableViewCell()
let (personName , personLocation) = people[indexPath.row]
cell.textLabel?.text = personName
cell.textLabel?.text = personLocation
return cell
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
}
Upvotes: 0
Views: 45
Reputation: 285092
You cannot use a table view cell initialized with the default initializer UITableViewCell()
Reuse the cell, add an identifier (e.g. PeopleCell
) in Interface Builder.
let cell = tableView.dequeueReusableCell(withIdentifier: "PeopleCell", for: indexPath)
And make sure that datasource
and delegate
of the table view are connected in Interface Builder, too.
Upvotes: 1