Skip to content

Instantly share code, notes, and snippets.

@chrislerum
Created February 17, 2015 22:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrislerum/0b1a85450c7fb87edf63 to your computer and use it in GitHub Desktop.
Save chrislerum/0b1a85450c7fb87edf63 to your computer and use it in GitHub Desktop.
app starts fine, tap button and picker shows, start to scroll picker, immediate crash
class MainViewController < UIViewController
def viewDidLoad
show_picker_button = UIButton.buttonWithType UIButtonTypeRoundedRect
show_picker_button.setTitle "Show Year Picker", forState: UIControlStateNormal
show_picker_button.frame = [[100, 100], [100, 50]]
show_picker_button.addTarget(self,
action: :show_year_picker,
forControlEvents: UIControlEventTouchUpInside)
self.view.addSubview show_picker_button
end
def show_year_picker
year_picker = YearPickerViewController.new
self.view.addSubview year_picker.view
end
end
class YearPickerViewController < UIViewController
def viewDidLoad
picker = UIPickerView.new
picker.backgroundColor = UIColor.whiteColor
picker.delegate = self
picker.dataSource = self
picker.showsSelectionIndicator = true
self.view.addSubview picker
end
def numberOfComponentsInPickerView pickerView
1
end
def pickerView(pickerView, numberOfRowsInComponent:component)
50
end
def pickerView(pickerView, titleForRow:row, forComponent:component)
(2000 + row).to_s
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment