开发者

how to place previously selected value at UIPickerview bar

I am displaying my array objects in a pickerview.

My array contains {one,two,three开发者_StackOverflow社区,four,five}

When I select a value in picker view, I am getting that value using

- (void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {

If I select two, exit from the picker view and for next time it display one in picker view bar.

But I need to display previously selected value.

I think this is understandable otherwise let me add comment.


you need to store the value of the selected row in a variable call it selectedRow and when the view appears use this method on the object of pickerView

- (void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component 
{
selectedRow = row;
}

- (void)viewWillAppear
{
  [picker  selectRow:selectedRow inComponent:0 animated:YES];
}

to select the row in the particular component.


- (void) viewDidAppear:(BOOL)animated 
{
[pickerView selectRow:selectedItem inComponent:0 animated:YES]; 
}


call method

- (void)selectRow:(NSInteger)row inComponent:(NSInteger)component animated:(BOOL)animated

After displaying it for second time


In case the pickerview was alloc/inited and then added as a subview at the view then

[picker selectRow:selectedRow inComponent:0 animated:YES]; 

works only after

[self.view addSubview:picker];    
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜