How to reload UIPickerView in iPhone? - iphone

hi
I am working on an iPhone app & i have to show some thing on a pickerview after receiving a response from socket, Methods of PickerView are check when application is going to be load. in my app i have to load PickerView on a button click.
After getting response in an array, When i click on button its shows a pickerview but empty. :(
SO can any body tell me how to reload the pickerview like tableView.
Thanx in advance

you could use either reloadAllComponents to realod all the component or reloadComponent to a zero-indexed number identifying a component of the picker view.
[myPickerView reloadAllComponents];
[myPickerView reloadComponent:IndexOfReloadComponent];
Read UIPickerView documentation

You can use below code, I hope it's work
[obj_Picker reloadAllComponents];

Call -reloadComponent: or -reloadAllComponents (methods on UIPickerView).
Quote:
You can dynamically change the rows of a component by calling the reloadComponent: method, or dynamically change the rows of all components by calling the reloadAllComponents method. When you call either of these methods, the picker view asks the delegate for new component and row data, and asks the data source for new component and row counts. Reload a picker view when a selected value in one component should change the set of values in another component. For example, changing a row value from February to March in one component should change a related component representing the days of the month.

Use this method - (void)reloadAllComponents of the UIPickerView class.

Related

Lazy Loading for multiple UITableView in one view

I am working on iPad app. And I am using 2 tables in one view and images urls are coming from
web services. I am using Apple provided lazy loading for both tables, and there are 2 web-service called for showing the two tables data, one is calling in ViewDidLoad() and second is calling in callback method of first web service. And I am facing problem in this method.
- (void)appImageDidLoad:(NSIndexPath *)indexPath withDataReceived:(NSData*)receivedData
The values for indexpath.row values are changing every time , some time it gives correct value and some time not.
Can anybody please help me for that.
Thanks in advance.
you might have to pass in which tableview also.. you kno how it is passing indexPath to that method.. modify it to pass tableview.. and inside the method.. check which tableView and then get the right data source array for appropriate tableview..

iPhone - Correct use of didSelectRowAtIndexPath

I'm a little confused as to how I should be using didSelectRowAtIndexPath.
Without using datasources (keeping things simple),if you display a list of names with UITableView and all you want to do is select a name and return it to whatever parent view controller created the UITableView list.. what would you do?
I'm used to Windows MFC programming where you have a dialog class and you call DoModal() to display the dialog and then query member variables of that dialog object to get the results.. With iPhone programming I'm confused with the whole paradigm. I push the UITableView into action, but at what point should I try and retrieve the results? pushViewController is asynchronous in nature isn't it? So I can't expect to retrieve results on the line immediately following the pushViewController method?
I'm using NSMutableArrays of NSStrings to keep things simple.
The patter you are going to use is called delegation, what happens is that you call the new ViewController and let it do its work, the function that called this will return normally,
Now you need to implement didSelectRowAtIndexPath and get the selectedRow, after this you will need to return the selected index or value to the original view controller( this will be recieved in another function) please read more about #protocol and delegateion

Page reloading in iPhone Application

Summary of the issue:
When I am loading some data into my iPhone application from a webservice, it populates the tableview two times with double number of records. I found that Viewdidload method is called two times causing this issue.
Scenario
From the first view I parse the webservice and collect the data into an array object.
This array object is being used by the second view to populate the tableview.
I am wondering what is behind reloading of the page causing the tableview has double number of records. Hope somebody can give me a hint.
You may want to consider calling applicationDidFinishLaunchingWithOptions in your app delegate, as this is only called during launch.
Thanks for the tips. What I found the issue was the way adding the view. i replaced [self.view addSubview:trlist.view] with [self presentModelViewController:trlist animated:NO]; and now it loads only one time.

Apple App UIPicker - how to make a multiple UIPicker?

I want to make multiple UIPicker with following requirements -
Make Multiple UIPicker (let's call them Picker1 and Picker2)
Value of Picker2 should automatically change based upon value of Picker1 (for instance I Picker1 has countries and Piker2 should display cities in that country)
also I would like to change the data in UIView based upon the value selected from Picker1 and Picker2 (lets say we select "UK" and city as "London" then UIView should talk only about "places to visit in london"
I know it sounds like lot of asking - your help would be highly appreciated, Thanks in advance.
First, your ViewController(the one with the picker) should implement the UIPickerViewDelegate.
You should than use this method:
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
It gets called every time you change a the selected row on any of the components of your picker.
For example when this gets called, you should change the UIView element to the appropriate value.
This is also the moment to reload Component2 (or whatever you want to call it) of your picker like this.
[picker reloadComponent:2];
or
[picker reloadAllComponents];

how to modify this code

I read the post Add UIPickerView & a Button in Action sheet - How?
I want to add data to the uipicker view from nsarray , specially I have two buttons that they will call different two uipickerview , so I cannot use the delegate of uipickerview
also what is the code to clise this uipickerview
any suggestion please
– pickerView:titleForRow:forComponent:
If you use that method you are acctually being passed the appropriate pickerview... so you can work out what pickerview you are dealing with from that. Its the same with most of the other delegate methods. So use that to work out what picker view you are dealing with and change the content accordingly.
To get rid of the actionsheet you can do:
[actionSheet dismissWithClickedButtonIndex:0 animated:YES];