tableview methods are been called only Once in Objective C on iphones? - ios4

i have tableview.In method 'viewWillAppear',it calls a function and function data is stored in an array named 'list'.Now in the method 'numberOfRowsInSection' method it returns the list count...and in another method 'cellForRowAtInexPath' it displays data in cell...now when the view is pushed to the above view using pushViewnavigationcontroller,function is called in viewwillappear and data is shown in tableview..now when i come back to previous view and move to tableview view again...viewWillAppear method is called(i checked using NSLog)...but tableview displays the same previous data..that means methods numberOfRowsInSection,cellForRowAtIndexPath are called only Once at first click..why is it so??and what can be done to load the tableview again and again with changing values of the data..??

I found the solution by myself. Just use [tableview reloadData] in method viewWillAppear.

Related

Two Primefaces datatables on same page cause filtering problems

I have a single page which includes two datatables. Their data are lazy loaded and paginated. To retrieve the rows that i need, i override the filterMap for the load() function. I pass this filterMap on the initialization of the LazyResult list. Unfortunately this causes problems with my filterMaps.
In detail:
1) On my page i got following lines to initialize both LazyLists, each for each table
<f:event type="preRenderView" listener="#{handler.initTable1}" />
<f:event type="preRenderView" listener="#{handler.initTable2}" />
2) In my ManageBean i am initializing the LazyList
public void initTable1() {
filterMap.clear();
filterMap.put("organization", "IBM");
lazyResults1= new ResultsLazyList<MyEntity1, MyBean1, MyDTO1>(
myBean1, filterMap);
}
public void initTable2() {
filterMap.clear();
filterMap.put("city", "London");
lazyResults2= new ResultsLazyList<MyEntity2, MyBean2, MyDTO2>(
myBean2, filterMap);
}
Inside the custom created ResultsLazyList, i am overriding the load method of LazyDataModel. Also note that i am passing as a paremeter the filterMap in the constructor (which used in the load method) so that i will have from the first run the results that i want.
Problem
Now, if i have just one table in my page, everything works fine. Adding more filters, sorting etc. Once i add the second table as shown above then the following happens.
Step 1) While the client page is loading, it calls first the initTable1 method. The lazyResults1 is initialized with the filterMap which is set in the constructor. The load method of lazyResults1 is not triggered yet and my filterMap at this point has the values organization=IBM
Step 2) While the client page is loading, it calls the initTable2 method. This overrides the values of my filterMap with city=London and initializes the lazyResults2. Note at this point the load method of lazyResults1 or lazyResults2 has not been triggered yet.
Step 3) Finally the load method lazyResults1 is triggered, but with the filterMap containing the values set in initTable2. So in the backend, my application tries to query on MyEntity1 with a field that exists on MyEntity2.
Question
1) Is there a way to somehow initialize lazyResults1 and trigger the load method so that my lazyResults1 is loaded with data before initTable2() is called and overrides my filterMap ?
2) I have seen some people using to ManagedBeans, each for each table, but i want to avoid this.
3) Another way is two pass 2 filterMaps in my ResultsLazyList constructor.
4) If there is another way to override the filterMap on the load method, then the way i am doing it, that would maybe solve my problem.
Two different tables, two different data sets... So why do you share filters between them? By reusing the same filterMap you're saying "I want the same filters to apply to both tables". If that's not what you want, then define separate filterMaps for each table.
1) Is there a way to somehow initialize lazyResults1 and trigger the load
method so that my lazyResults1 is loaded with data before initTable2()
is called and overrides my filterMap ?
These are just hacks because you're trying to have it both ways - to share and not share filters simultaneously.
Let's say the filters were exposed in UI like this:
And the user changes the "Year" filter. Do you expect this change to affect some other table? Probably not. Because this set of filters belongs to this table only.

Passing an object from a tabbarController to its subviews

I am trying to pass a simple core data objects info from a tabBarController to its subviews so that they each reference a different attribute of that object. As a newbie, I'm not sure even where to start. It doesn't seem to be as simple as passing the data from one tableView to another...
Thank you for any help.
If you are sharing the same object between (most of the) the view controllers of your tab bar controller, maybe the best architecture for this would be to have one central data object.
A typical pattern is a singleton, some kind of data manager that provides the object, but maybe that is overkill. Another is to keep references to all view controllers and update them one by one when something changes - also not very elegant.
What you really want is something like a global variable. You could (ab)use your app delegate (just give it a property that points to the object) or if you prefer even your tab bar controller (make a subclass, give it a property). In the latter case, every view controller could then get the object like this:
NSManagedObject *object = [(MyCustomTabBarController*)self.tabBarController object];
For example, you can check for changes and refresh your views in viewWillAppear.
A UITabBarController should be handling other view controllers, not handling data objects. How does the tab bar controller get the object reference in the first place? And what is the object you're sharing?
Let each of your subordinate VC's keep a pointer to the object, and then they can each follow the appropriate keypath to get to the entities they're designed to handle.
Tim Roadley's book Learning Core Data for iOS, in chapters 5 and 6, shows how to pass an object from one view controller (a table view) to a detail view. It doesn't sound like that's what you're asking, but just in case...
In response to comment:
I'm looking at a tableview, tap a cell, and then a tab bar controller slides in? That's not the usual visual metaphor for a tab bar; it's meant for changing modes for the entire program. See the Music app for a typical example: songs, playlists, artists.
But if you really need to do it that way, try this (I'm assuming you're using storyboards):
In prepareForSegue: in your tableview controller, tell the destination (tab bar controller) what object it's working with.
In the tab bar controller's -viewWillAppear, tell each of its tabs about the attribute: self.frobisherViewController.frobisher = self.myWidget.frobisher.
You could instead tell each of the component tabs about the top level object: self.frobisherViewController.widget = self.myWidget. But I like the first approach better because there is less linkage. The frobisherViewController now would need to know about both widgets and frobishers.
This ended up being very simple. I was trying to call the object in the child views initWithNibName which doesn't work. I ended up creating a setObject function and calling the properties I wanted in viewWillAppear.
Hope this helps someone.

Search operation in javafx tableview

I used the tutorial on link TUTORIAL LINK
Now I want to perform the search operation on tableview to search for table row contents to match the query.
So is there any way to to search for items in tableview.
Something I found in c# was the LINQ query which search in the list for condition.
Is there something similar in javafx.
Seems, there is nothing similar. You can file a RFE, or a Tweak, in JavaFX-2 jira, if you want to have such functionality (if it doesn't exist yet).
Or, if you know, how should it look like, you can talk to author of TableView, and implement it by yourself, and push according patch in an open javafx.
Practically, you can do a search over a collection of content of TableView, and apply value factory of each column for according value, and check, if it returns an appropriate value/content.
I saw a project like this once.
Maybe this is what your looking for: Advanced TableView
Sadly i have no idea how they implemented it.
EDIT The page i linked to states that you should go to the following page: TiwulFX
this is search method, where data is your list ,
private boolean search(String a ){
int i=0;
do{
if(data.get(i).getNom().equals(a) )
{
return true;
}
i++;
}while(data.size()>i);
return false;}
1) Get your TableView object
2) Call getItems() method on it
3) Call get() method the parameter for this method is the index of your object
TableView<String> tableView = new TableView<>();Now, suppose that we've already filled tableView with Products objects
You can reach to every object this way
tableView.getItems().get(0)
This will return the first object you added to tableView
I Hope This Helps ^_^

How do I set distance to annotation in tableview?

I have an app that fetches web data and stores it in CD-db. So far, FirstViewController (MKMapView) fetches CD-db into NSMutableArray and uses its values to plot locations by getting the array of custom objects from the db. I cycle thru a for loop while creating the annotation (pin). Each pin gets its distance property set from a calculation I use for the distance from userLocation to each pin.
This app runs in a tabbarcontroller and the other tab is a tableview listing of these locations. I get the values for that tableview by fetching the CD-db and getting the array's values at cellForRowAtIndexPath method and putting the values into the cell.textLabel etc...
My question is, since the distances from userLocation to each pin are calculated on the mapview controller, how do I get those distances on the tableview controller?
You could set the mapview controller as the tableview's datasource. That way only one viewcontroller fetches data. Once you build the mapview controller's array of custom objects it can be used to respond to all the tableview datasource calls such as cellForRowAtIndexpath and numberOfRowsInSection

UITableView not loading data the second time

I have a UITableView and I call reloadData in the viewWillAppear method
- (void)viewWillAppear:(BOOL)animated {
[tableView reloadData];
}
However, the second time my view appears, neither numberOfRowsInSelection nor cellForRowAtIndexPath are called
What could I be doing wrong?
I am seeing the same problem and yes, using a breakpoint I have already confirmed that viewWillAppear is called and reloadData executed - but cellForRowAtIndexPath is never called and the table contains stale data.
New information: I tried creating a new class/nib, this time using a UITableViewController instead of a UIViewController and implementing the delegate & datasource interfaces manually. This works as expected - cellForRowAtIndexPath is called and the table is updated. There must be something else UITableViewController does for me that I need to implement in my version, but I don't know what it is....
Solved! My issue, anyhow. I had wired up the datasource and controller connections, but hadn't connected the tableView outlet in my class to the table in the UI builder. smacks forehead. Mine works now, hope this helps!

Resources