-1

In my swift code what I would like to do is segue a name from a table view cell to a new class. I do not want to do the the navigation bar with the built in library from any of this operation. The code should segue the text on the table view when the user touches the table view cell to class two in display on label lbl. Everything should be done in storyboard.

class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
    var itemName: [NSManagedObject] = []
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return itemName.count
    }

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let title = itemName[indexPath.row]
        let cell = theTable.dequeueReusableCell(withIdentifier: "MyCell", for: indexPath)
        cell.textLabel!.numberOfLines = 2
        cell.selectionStyle = .default
        let attr1 = title.value(forKey: "name") as? String
        
        let text = ["  :  ", attr1].flatMap { $0 }.reduce("", +)
        cell.textLabel?.text = "Item \(indexPath.row + 1) \(text)"
        
        cell.textLabel?.textAlignment = .center
        
        cell.layoutMargins = UIEdgeInsets.zero
        
        cell.preservesSuperviewLayoutMargins = false
        cell.separatorInset = UIEdgeInsets.zero
        cell.layoutMargins = UIEdgeInsets.zero
        
        return cell
    }
}

class Two: UIViewController {
    var lbl = UILabel()
    
    override func viewDidLoad() {
        super.viewDidLoad()
    }
}

enter image description here

enter image description here

koen
  • 5,383
  • 7
  • 50
  • 89
Sam Burns
  • 65
  • 1
  • 10
  • Create a segue in storyboard. If your scene isn't embedded in a navigation controller then you will get a modal presentation – Paulw11 Aug 27 '23 at 07:31

0 Answers0