Post

Replies

Boosts

Views

Activity

How do I programmatically implement editing of a UITableViewCell?
I have a UITableView added as a subview to a UIViewController and I used the built-in editButtonItem with self.navigationItem.rightBarButtonItem = editButtonItem Also, after reading other forum threads, I called these functions: func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool { return true } override func setEditing(_ editing: Bool, animated: Bool) { super.setEditing(editing, animated: true) tableview.setEditing(editing, animated: true) } When I tap "Edit", it does toggle the red minuses for each cell and it changes to "Done", but I still can't edit the text for the cells. Am I missing something?
1
0
727
Apr ’22
How do I access stored properties from another UIViewController programmatically?
How can I add append addedItem in SecondViewController to items array in FirstViewController programmatically? class FirstViewController: UIViewController, UITableViewDelegate, UITableViewDataSource { var items: [String] = [] } class SecondViewController: UIViewController { let textField: UITextField = UITextField() let saveButton: UIButton = UIButton() @objc func saveButtonTapped() { let addedItem = textField.text } }
1
0
753
Mar ’22
Value of type 'UITableViewCell' has no member 'nameLabel'
I can't figure out how to solve the error: Value of type 'UITableViewCell' has no member 'nameLabel' The line that throws this error in the code below is: cell.nameLabel.text = item.name, which is at the bottom just above the return cell line. This may or may not be useful to know, but this is a lesson in a Sololearn course for Swift. import UIKit class ItemTableViewController: UITableViewController { var items = [Item]() func loadSampleItems() { items += [Item(name: "item1"), Item(name: "item2"), Item(name: "item3")] } override func viewDidLoad() { super.viewDidLoad() loadSampleItems() } override func numberOfSections(in tableView: UITableView) -> Int { return 1 } override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return items.count } override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: "ItemTableViewCell", for: indexPath) let item = items[indexPath.row] cell.nameLabel.text = item.name return cell }
3
0
3.4k
Aug ’21