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.
Related
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..
I have 5 view controllers, which are in a navigation controller hierarchy. When I reach my last view controller, there's a button that lets me go back to the "Home" view controller (named CardWalletViewController) which is a table view controller. Here's the method I have in my last VC (PointsResultsVC)
- (IBAction)homePressed:(id)sender {
NSArray *VCs = [self.navigationController viewControllers];
[self.navigationController popToViewController:[VCs objectAtIndex:0] animated:YES];
}
CardWalletVC's cells is being filled up by values coming from the saved instances of a Card in NSUserDefaults and it works fine.
Now, what I want is to update the value in my CardWalletViewController, which is the points of a card coming from my PointsResultsVC. Note that this points is saved in NSUserDefaults.
Upon the process of trying to update of the value shown in my CardWalletVC, I placed [self.tableView reloadData]; inside -viewDidLoad, -viewWillAppear, and -viewDidAppear of the said class. I tried placing it one by one in each of this methods, yet it doesn't seem to work.
Advice Please.
EDIT: problem solved
This one served as my guide Save data from one tab and reloadData in another tab.
And as I have discovered, -viewDidLoad of a certain class will only be called once, all throughout runtime of app. Whereas -viewWillAppear, it will be called every time the view appears.
So, I just moved the way I am loading the values saved in NSUserDefaults from -viewDidLoad to -viewWillAppear. Also, inside -viewWillAppear I placed the [self.tableView reloadData]. Then there, problem solved.
There's a lot of things that could be going wrong so you'll need to provide more info to narrow it down.
First of all, viewDidLoad will not be called so you can remove it from here. Both viewWillAppear and viewDidAppear will be called, so you only need it one of these 2 methods.
Next, you need to determine what the actual issue is.
1 - is self.tableView a proper reference to the table? Are you properly maintaining the reference?
2 - is the table actually reloading but using the old data, or is it not reloading at all? You can log the willDisplayCell method to see what is going on when the view appears.
With that info, the root cause can be narrowed down to a solvable problem.
I have an iPhone app that starts in a table view and goes to a different table view when the user selects a cell. The two table views are in separate classes (or whatever the proper Objective-C term is, ie. 2 different .h and .m files), and the second table view makes a request from a server based on the selection in the first table. There is a noticeable delay and I've been trying to put a UIActivityIndicatorView up when that happens, but that only displays for a split second when view segues to the second table view. I know this is an issue with threading, but I can't get this to work following any of the other posts on this topic. I call my startAnimating in didSelectRowAtIndexPath and the stopAnimating in the viewDidDisappear. I have also tried using the following code to get this to work by calling it in the didSelectRowAtIndexPath: [activityIndicator performSelectorInBackground: #selector(startAnimating) withObject: nil]; How do I make the activity indicator (or any loading animation for that matter) to work when the server request is going on?
I see that this is a frequent problem on Stack Overflow, but I did just find a working solution. I found this forum iphonedevsdk.com/forum/tutorial-discussion/… My issue was a synchronous connection taking up my main thread, so starting the spinner and then calling the connection in a separate method does the trick.
I am using XCode 4.0.1. I have to different views with UITableView. Data is coming from server. I am parsing JSON data and displaying it to tableview. I am using reloaddata method to display data on tableview. But mostly It is not displaying anything(It is not calling tableview delegate methods) but sometimes functioning normally. I am calling URL at ViewWillAppear, calling reloaddata on connectiondidfinishloadingdata.
I am experienced programmer for iphone but this is unexpected to me. Any Suggestions. Thanks in advance.
May be you should call your update on the main thread.
im writing a news app, and im just planning it out in my head and need some help, before i start coding.
my app is a tab bar controller that is loading and displaying info from an xml feed. i am going to start the download of the xml within the app delegate in the background, so the app does not get closed down by the os, however this means that when my first table loads it will be blank , so i need a way of reloading the table once it has finished . i have encountered this issue before and couldnt work a way round it
last time i started the download of the info from the viewdidload method in the first view controller and tried a reloaddata , but that didn't seem to work. has anyone got a work around for this problem?
[yourTable reloadData] is the way to go.
Make sure to call it on the main thread, and that your data structure is actually holding the correct data.