swiftxcodeviewcontrolleroutlet

I cannot connect label as outlet in a ViewController


In my storyboard there are 2 labels, 1 button, 1 UIImage and 1 table View. I am able to connect those button, UIImage and table but cannot connect the 2 labels as outlet in my ViewController class. I am holding control and drag it as usual but it does not do anything. I already set the custom class of the storyboard as my ViewController class.

Solution I have done: Delete the derived data folder but didn't solve the problem.

Thanks for your time and I am very appreciated by your help.

enter image description here

So as the Image shows, my ViewController in the main.storyboard already has the custom class ViewController, I was able to connect the button (add activity), the UIImage and the table View, but cannot connect the two labels (which show time and date)

Part of my code in the ViewController class :

import UIKit

let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)


class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource, CanReceive {

    var todoList = [ToDo]()
    let cellId = "CellId"
//    let test = ["Row1", "Row2", "Row3"]
//    let imageName = ["anchor", "arrow-down", "aperture"]
    @IBOutlet weak var ImageTop: UIImageView!
    @IBOutlet weak var tableView: UITableView!

    override func viewDidLoad() {
        super.viewDidLoad()
        self.tableView.register(UINib(nibName: "CustomTableViewCell", bundle: nil), forCellReuseIdentifier: cellId)
        configureTableView()
        ImageTop.image = UIImage(named: "todo-background")
        }

    }

Solution

  • When these type of problems usually happen for me I just restart XCode and launch the project again, then wait for XCode to finish indexing all the files and try to launch application. After application launched/failed to launch, try to bind outlet to required class and it usually fixes the problem.

    Another thing you could try to do is launching the following in XCode: Product -> Clean Build Folder...


    Good luck :)