Created
June 7, 2016 21:40
-
-
Save pyrabbit/9a6ede2be370ca9a079f713ef76130ad to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// StylePickerViewController.swift | |
// ConsultantAide | |
// | |
// Created by Matt Orahood on 5/28/16. | |
// Copyright © 2016 Matt Orahood. All rights reserved. | |
// | |
import UIKit | |
import CoreData | |
class StylePickerViewController: UIViewController, UIPickerViewDataSource { | |
@IBOutlet weak var stylePicker: UIPickerView! | |
var pickerData : [String] = [] | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
stylePicker.hidden = true | |
// Do any additional setup after loading the view. | |
stylePicker.dataSource = self | |
collectStyleNames() | |
stylePicker.hidden = false | |
} | |
func collectStyleNames() { | |
let app = UIApplication.sharedApplication().delegate as! AppDelegate | |
let context = app.managedObjectContext | |
let fetchRequest = NSFetchRequest(entityName: "Style") | |
do { | |
let results = try context.executeFetchRequest(fetchRequest) | |
for item in results { | |
pickerData.append(item.name) | |
} | |
} catch let err as NSError { | |
print(err.debugDescription) | |
} | |
} | |
override func viewWillAppear(animated: Bool) { | |
super.viewWillAppear(animated) | |
self.navigationController?.navigationBarHidden = false | |
} | |
override func didReceiveMemoryWarning() { | |
super.didReceiveMemoryWarning() | |
// Dispose of any resources that can be recreated. | |
} | |
func numberOfComponentsInPickerView(pickerView: UIPickerView) -> Int { | |
return 1 | |
} | |
func pickerView(pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int { | |
return pickerData.count | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment