Hi Everyone,
I was wondering if I could have some help please?
I’m trying to populate a pickerview with numbers from 1 to my integer count (number of questions in my plist).
I’ve got this so far
import Foundation
import UIKit
class PickerView: UIViewController, UIPickerViewDataSource, UIPickerViewDelegate {
var Category: String!
var numbDict: String!
var QuestionNumber: String!
var cell: UITableViewCell?
var currentTopicIndex = Int()
var setCount = Int()
var setNumber = Int()
var pickerString2 = [String]()
var selectedQuestionNumber: String!
var contacts: NSArray?
var dictContacts = Int()
var data = [String]()
var pickerArray: NSArray?
var competitionArray:NSMutableArray = []
@IBAction func backBtn(_ sender: AnyObject) {
navigationController?.popToRootViewController(animated: true)
}
@IBOutlet weak var questionNumberPicker: UIPickerView!
@IBOutlet weak var numberOfRow: UILabel!
@IBAction func checkoutlet2(_ sender: AnyObject) {
NSLog ("\(self.pickerString2)")
NSLog ("\(self.Category)")
NSLog ("\(self.selectedQuestionNumber)")
}
override func viewDidLoad() {
super.viewDidLoad()
print(currentTopicIndex)
// UIApplication.sharedApplication().statusBarStyle = .LightContent
// self.navigationController!.navigationBar.isHidden = true
self.questionNumberPicker.delegate = self
self.questionNumberPicker.dataSource = self
setCount = Quiz.quizzes[currentTopicIndex].plist.count
numbDict = String(setCount)
pickerArray = Array(1…setCount) as NSArray
let pickerString2 = pickerArray
print(pickerArray)
print(pickerString2)
self.questionNumberPicker?.reloadAllComponents()
self.questionNumberPicker = UIPickerView()
// self.numberOfRow.text = self.pickerString2[0]
print(self.pickerString2)
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if(segue.identifier == "questionToQuiz"){
// Get the new view controller using [segue destinationViewController].
let detailScene = segue.destination as! QuizController
detailScene.numberOfQuestions = numberOfRow.text as String!
}
}
func numberOfComponents(in pickerView: UIPickerView) -> Int {
return 1
}
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
return pickerString2.count
}
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
return pickerString2[row]
}
func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
let selectedRow = pickerString2[row]
numberOfRow.text = selectedRow
selectedQuestionNumber = pickerString2[row]
}
// Do any additional setup after loading the view.
}
but it keeps coming up with a pickerString2 of 0. Can anyone see why this is?
I would appreciate any help you can offer. Many thanks in advance