How to get a function called when picker view list updates?

Go To StackoverFlow.com

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.

2012-04-05 16:56
by xtrimsky


2

I think you are looking for [pickerView reloadAllComponents];

this will reload all the components of the picker view

2012-04-05 17:35
by Ankit Srivastava
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 - xtrimsky 2012-04-05 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 2012-04-05 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 - xtrimsky 2012-04-05 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-exampl - Ankit Srivastava 2012-04-05 18:02
Awesome it worked!, thank - xtrimsky 2012-04-05 18:39


1

use

-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
some method;
}
2012-04-05 17:00
by Eric
be sure to also add the PickerViewDelegat - Eric 2012-04-05 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 confusio - xtrimsky 2012-04-05 17:13
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 2012-04-05 17:16
Ads