0

I've got a pickerview.
I would like to call a specific function each time the list changes (an item is added or removed).
How would I be able to do that ? I have tried a few IB Actions but could not get the function triggered.


Extra:

Here is a little bit more about the project just in case you have a better idea:

I have a ViewController, which has a picker view.
I have a View, that on click of a button, calls a class DataHolder, which ads an item to a dictionary.
This dictionary is linked to the picker view, the picker view updates.

Andrei
  • 1,183
  • 2
  • 19
  • 40

2 Answers2

2

I think you are looking for [pickerView reloadAllComponents];

this will reload all the components of the picker view

Ankit Srivastava
  • 12,347
  • 11
  • 63
  • 115
  • I would like a fonction to be triggered when the picker view gets reloaded. The picker view gets reloaded in multiple places of my app (not entirely sure where, I am continuing a project) – Andrei Apr 05 '12 at 17:46
  • fire a notification as soon as you call the reload pickerview method and listen for the notification in other parts of the app and do what you need to do. – Ankit Srivastava Apr 05 '12 at 17:49
  • Could you guide me where I must look to do this ? I'm very beginner in Obj-C. What would be the name of the object that would allow me to do that ? Its basically making a view, call a function in another unrelated view. – Andrei Apr 05 '12 at 18:00
  • This might not be the best approach depending upon your requirement.. but still you can look into it here http://stackoverflow.com/questions/842737/cocoa-notification-example – Ankit Srivastava Apr 05 '12 at 18:02
1

use

-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
some method;
}
Eric
  • 4,063
  • 2
  • 27
  • 49
  • be sure to also add the PickerViewDelegate – Eric Apr 05 '12 at 17:03
  • I meant if the list changes, like if an item gets added or removed. not if the user changes the selected element. sorry for the confusion – Andrei Apr 05 '12 at 17:13
  • 1
    that would be a change to the array that makes up the Picker. Some method would need to be called to change the array anyway, so why not add your desired method there? – Eric Apr 05 '12 at 17:16