swift scroll to tableviewcell
let indexPath = IndexPath(row: row, section: section)
tableView.scrollToRow(at: indexPath, at: .top, animated: true)
swift scroll to tableviewcell
let indexPath = IndexPath(row: row, section: section)
tableView.scrollToRow(at: indexPath, at: .top, animated: true)
swift table view needs
func setTableNeeds(){
tableView.delegate = self
tableView.dataSource = self
let nib = UINib(nibName: "cell", bundle: nil)
tableView.register(nib, forCellReuseIdentifier: "cell")
}
extension NameOfUIViewController: UITableViewDelegate, UITableViewDataSource{
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 10 //number of cells
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! Cell //CustomCell Name if the is one
//cell.blah = blah or cell.blah(blah: blah).....
return cell
}
}
write into table view swift 5
import UIKit
// First, Consider using a UITableViewController
class ToDoListViewController: UITableViewController {
// 1. Define an array with to-do list items
let itemArray = ["Study Swift", "Buy Eggs", "Read a newspapper"]
override func viewDidLoad() {
super.viewDidLoad()
}
// 2. Return a number of rows according to the number of array elements
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return itemArray.count
}
// 3. Assign the tableView cell and title
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "ToDoListCell", for: indexPath)
cell.textLabel?.text = itemArray[indexPath.row]
return cell
}
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us