I am trying to work on this piece of code from a project I downloaded and trying to use in my code. In the viewDidLoad, a pickerView is populated either by "New Puzzle" or if a user saved a game in the previous VC, the saved game. The way this was originally written, the user saved the game and with a segue came back to this controller with the pickerView. In my "mod", I embedded the two VC in a navigation controller, thus getting a nice Back button to go back to the pickerView controller. However, loading the pickerView is in the viewDidLoad function, which my understanding is, is loaded only once.
Can someone please help me, on which items from the viewDidLoad need to be moved. And when moved, would they need to go into a viewWillAppear, or viewDidAppear? My understanding is it should be in the viewWillAppear.
override func viewDidLoad() {
super.viewDidLoad()
navigationItem.title = "Games"
DispatchQueue.main.async {
if !Settings.shared.adsEnabled {
self.removeTableViewHeader()
} else {
//self.tableView.layoutTableHeaderView()
}
}
//Picker Stuff
// Connect data:
self.picker.delegate = self
self.picker.dataSource = self
copyDatabaseIfNeeded("puzzles")
// open database
if sqlite3_open(finalDatabaseUrl2.path, &db2) != SQLITE_OK {
//print("error opening db")
}
else{
}
pickerData.append("New Puzzle")
//retrieve all dates from previous puzzles and add them to pickerview
var queryStatement2 = ""
queryStatement2 = "SELECT * FROM puzzle;"
self.statement2 = nil
if sqlite3_prepare_v2(self.db2,queryStatement2,-1,&self.statement2,nil) == SQLITE_OK{
while(sqlite3_step(self.statement2) == SQLITE_ROW){
let date = sqlite3_column_text(self.statement2,2)
let comp = sqlite3_column_text(self.statement2,3)
let dateString = String(cString: date!)
let compString = String(cString: comp!)
pickerData.append("\(dateString) - \(compString)")
}
//sqlite3_reset(self.statement2)
sqlite3_finalize(self.statement2)
}
}