Am1rFT
Am1rFT

Reputation: 177

Pressing table view cell

I'm almost new to Swift and as a self study I'm populating a tabel with some JSON data that I receive from an API. each cell would have a specific name and whenever I press each cell I need to open a page to show some data that they will be received from an API.

Should I design multiple pages to different cell or can I have just one page?

override func numberOfSections(in tableView: UITableView) -> Int {
    return 1
}

override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return Global.GlobalVariable.names.count
}

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = UITableViewCell()
    let content = Global.GlobalVariable.names[indexPath.row]
    cell.textLabel?.text = content
    cell.accessoryType = .disclosureIndicator

    return cell
}

I'm populating each cell like this.

Upvotes: 0

Views: 34

Answers (1)

maldahleh
maldahleh

Reputation: 313

You can make use of another view controller that is displayed when a row is selected, and set up a segue between your table view controller and the secondary view controller.

You would want to conform to the UITableViewDelegate in your table view controller, and implement tableView(_:didSelectRowAt:) so that you are informed when a row is selected, you can then programatically preform the segue to the detail view controller.

Upvotes: 1

Related Questions