Unrecognized selector sent to instance error

We have a runtime error that we can’t seem to solve… we are building a page with segmented control and a table view, I’ll show you our code and the error, can you please help us? Thanks!

And this is the code 1/2


It’s a little hard to read the photographs you have sent so the following is recommenced.

When you post images of your code, use the built in screenshot app rather than take a photograph. Photographs of code are sometimes unclear and very hard to view.

With the Mac ScreenShot App, you can capture the entire window, the entire screen or a section of the screen.

If you just want a small section, press Shift + Command + 4 which will change your mouse pointer into a set of crosshairs. Click and drag diagonally across the screen to capture the section you want. When you let go of the mouse button, the image will be saved to your Desktop and will be named something like “Screen Shot YYYY-MM-DD at HH.MM.SS am/pm”.

Other options are available by pressing Shift + Command + 5 and an options bar will appear near the bottom of the screen.

The other alternative way to provide code to examine is to paste your code into a reply. Place three back-ticks ``` on the line above and below your code segment so that it is formatted nicely to read.

Hey Chris! very sorry for the inconvenience
gonna paste the code on here, Thanks!

import UIKit

class SegmentedControlViewController: UIViewController, UITableViewDelegate, UITableViewDataSource,UISearchBarDelegate{
    @IBOutlet weak var controller: UISegmentedControl!
    @IBOutlet weak var tableView: UITableView!
    @IBOutlet weak var search: UISearchBar!
    let activities = ["المشي","الدراجات","الرماية", "التنس", "كرة القدم", "سكواش", "الهايكنج", "الجري"]   // let means value cannot be edited
    let locations = ["location1","location2"]
    let users = ["user1","user2"]
    let trainers = ["trainer1","trainer2"]
    //var filteredData: [String]!
    override func viewDidLoad() {
        tableView.delegate =  self
        tableView.dataSource = self
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        switch controller.selectedSegmentIndex {
        case 0:
            return activities.count
        case 1:
            return locations.count
        case 2:
            return users.count
        case 3:
            return trainers.count
        return 0
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath)
         switch controller.selectedSegmentIndex {
        case 0:
            cell.textLabel?.text = activities[indexPath.row]
        case 1:
            cell.textLabel?.text = locations[indexPath.row]
        case 2:
            cell.textLabel?.text = users[indexPath.row]
        case 3:
            cell.textLabel?.text = trainers[indexPath.row]
        return cell
    @IBAction func segmentChanged(_ sender: UISegmentedControl) {


I placed your code into a test UIKit project, set up a storyboard with a segmented Controller at the top and a table view underneath. Selected one prototype cell and set the cell Style to Basic rather than Custom. Connected the storyboard elements to the ViewController and it works.

Without knowing the context in which this ViewController is in your overall project it’s a bit hard to know what to suggest.

Hey chris, it runs fine but have you tried to change the segment? this is our issue whenever we try to change the segment the runtime error pops up

The segment works perfect. See the video of it here.

Hey! it works perfectly now thanks!
is it possible to retrieve firestore documents and display them in the proper segment?
if so, can you please help me out or provide resources that will? thanks!

I’m afraid you will have to figure out that for yourself.