Friday 21 November 2014

Jogendra Singh

UIPickerView make in Swift iOS


How to make or create UIPickerView in swift language


What is pickerview : - UIPickerView use for user select value by rotating the wheel for his desired value.  In pickerview have rows and component for user interface .  


Going to learn UIPickerView : -  

                  Open xCode and create new project UIPickerViewSwift  and select Swift language .


Now go in ViewController.swift and create Object of picker view 

    @IBOutlet
    var pickerViewObj : UIPickerView!

  Now go in storyboard and drag and drop UIPickerView and connect to object like this :- 






also connect delegate and datasource  

adding datasource and delegate in ViewController.swift

class ViewController: UIViewController ,UIPickerViewDataSource, UIPickerViewDelegate  {
          }



Create content array that you want to show on PickerView

    var pickerValueArray = ["Welcome", "on", "our", "site", "jogendra.com"]

Add datasource and delegate function of pickerview

  func numberOfComponentsInPickerView(pickerView: UIPickerView) -> Int
    {
        return 1;
    }
    
    // returns the # of rows in each component..
    func pickerView(pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int
    {
        return pickerValueArray.count;
    }

//Title showing
    func pickerView(pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String!
    {
        return pickerValueArray[row]
    }

  For Selection value add this 
    func pickerView(pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int)
    {
        NSLog("Value Printing %@",pickerValueArray[row]);
        
     }






Thanks for Visit  , Also can visit on My blog Facebook page iPhone & iPad Application Development Help World and also can visit Google+ 






Jogendra Singh

About Jogendra Singh -

I'm Founder of Jogendra.Com. I love to share my bright ideas with the whole blogging community. I'm a good iPhone Application Developer. Apart from Blogging, I love to play Cricket and mobile games (Clash of clans).

Subscribe to this Blog via Email :