-2

I have an app where the user scans a QR code into an NSString, which I then need to put into a UIPickerView.

What would I use to set the text of the UIPickerView row as the NSString from the QR code?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
  • 1
    You need to add string in a array, and then reload the picker view, you can check following thread on how to use picker views -http://stackoverflow.com/questions/6636237/uipickerview-programatic-example – rishi Jun 20 '14 at 04:16

1 Answers1

0

Firstly, you need to have an array of strings and implement the UIPickerViewDataSource and UIPickerViewDelegate in your .h file. After this, you will have to make use of the delegate methods of UIPickerView like as shown :

-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
    //return number.
}

This will return the number of sections that you want in your pickerView.

(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
    return array.count;
}

The above method will return the number of rows in particular component. If you have an array, then probably it will be equal to the number of elements in your array. And finally this last one.

-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
    NSString *str;
    if(pickerView == yourPickerName)
    {
        str = [array objectAtIndex:row];
    }
    return str;
}

This method will return the text value for each row in your picker. And don't forget to connect your pickerView's datasource and delegate in your Storyboard.

Hope this helps.

Dhrumil
  • 3,221
  • 6
  • 21
  • 34