Reputation: 245
I am pretty new to programming and I am trying to insert a picker view. I think my code is right, but when I build the app it is blank. I have no idea what I am doing wrong.
My code is as follows:
import UIKit
class LookingController: UIViewController, UIPickerViewDelegate {
var iama=["dude","lady"]
func numberOfComponentsInPickerView(pickerView: UIPickerView!) ->Int{
return 1
}
func pickerView(pickerView: UIPickerView!, numberOfRowsInComponent component: Int) ->Int {
return iama.count
}
func pickerView(pickerView: UIPickerView!, titleForRow row: Int, forComponent component: Int)->String!{
return iama[row]
}
}
Any suggestions??
Upvotes: 1
Views: 1489
Reputation: 71854
I think you forgot to add pickerView into your view so follow this step.
Go to the Storyboard, drag a Picker View from the Object Library to the top of the View Controller inside the Storyboard.
The Storyboard should look like this.
The Picker View must conform to the UIPickerViewDataSource and UIPickerViewDelegate protocol. Ctrl-click the Picker View and drag from the dataSource Outlet to the View Controller in the Document Outline. Repeat this step for the delegate Outlet.
from the reference : http://www.ioscreator.com/tutorials/picker-view-tutorial-ios8-swift
May be this will help you.
Upvotes: 2