I am having trouble creating a function that will return the selected value from a picker wheel on my app.
This is what I have so far:
@IBOutlet weak var lstPriority: UIPickerView!
// Array for picker wheel items
let lstPriorityOptions = ["Low", "Medium", "High"]
// Function to get selected value from picker wheel
public func GetSelected() -> String {
let pickerView: UIPickerView
let valueSelected = lstPriorityOptions[row] as String
return valueSelected
}
// Button click event, this is where I will be calling the above function
@IBAction func btnAdd(_ sender: Any) {
if txtNewItem.text != "" {
let newToDoItem = ToDoItem(ToDoItemText: txtNewItem.text!, ToDoItemPriority: GetSelected())
ToDoItemList.append(newToDoItem)
txtNewItem.text = ""
}
}
-(IBAction)doneYearPickerAction:(id)sender
{
if ([strPickerSelectedYearIndex isEqualToString:@""]) {
self.yearTxt.text = [yearArr objectAtIndex:0];
}else{
self.yearTxt.text = [yearArr objectAtIndex:[strPickerSelectedYearIndex intValue]];
}
// hides year pickerview
[_yearPickerView setHidden: YES];
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.