ios - How to set title for row in PickerView in Swift 3? -
i need give title rows according array don't know how this. i'm new ios.
class viewcontroller: uiviewcontroller , uipickerviewdelegate, uipickerviewdatasource{ @iboutlet weak var pickerview: uipickerview! @iboutlet weak var label: uilabel! var names: array<string>? var department: array<string>? override func viewdidload() { super.viewdidload() // additional setup after loading view, typically nib. names = ["vineeta", "shubham" ,"anand", "vivek", "akshay", "harshit", "vikas", "prasoon", "sunil"] department = ["ios","angular", ".net", "ios","ios", ".net", "android","android", "angular"] } override func didreceivememorywarning() { super.didreceivememorywarning() // dispose of resources can recreated. } func numberofcomponents(in pickerview: uipickerview) -> int { return 2 } func pickerview(_ pickerview: uipickerview, numberofrowsincomponent component: int) -> int { return 9 } func pickerview(_ pickerview: uipickerview, titleforrow row: int, forcomponent component: int) -> string? { if component == 0 { [names o] } } }
use code -
func pickerview(_ pickerview: uipickerview, numberofrowsincomponent component: int) -> int { if component == 0 { return names?.count } else return department?.count } func pickerview(_ pickerview: uipickerview, titleforrow row: int, forcomponent component: int) -> string? { if component == 0 { return names?[row] } else { return department?[row] } }
Comments
Post a Comment