Note that there are some explanatory texts on larger screens.

plurals
  1. PORefreshing the content of TabView
    primarykey
    data
    text
    <p>Ok I am trying to refresh the tab content of each of my tabs after a web call has been made, and I have tried soo many different methods to do this that I have lost count. Could someone please tell me how this is possible? </p> <p>The web call just calls JSON from a server and uses it to update the content of the tabs. For testing purposes I have a button set up inside my settings class. Settings class is a view within the home tab which has a button called refresh. When clicked this takes JSON stored on the device which is different to the one called from the web call on application start up. This saves me having to change the JSON on the server.</p> <p>I will take you through some of the techniques I have tried and would be grateful if someone could tell me what I am doing wrong.</p> <p>I tried making an instance of the class and calling the refresh method like this</p> <pre><code>DashboardVC *db = [[DashboardVC alloc] init]; [db refreshMe]; </code></pre> <p>The refresh method in dashboard class is this </p> <pre><code>-(void) refreshMe { [self loadView]; [self viewDidLoad]; } </code></pre> <p>However no luck. This method will work if I call it inside the Dashboard class, but wont work if I call it from another class. I think it is become I am instantiating a new class and calling refresh on that. So I dropped that technique and moved onto the next method</p> <p>This loops through all the tabBars and changes the tabTitles without any issues, so it I know it is definitely looping through the ViewControllers properly.</p> <p>I also tried every varient of the view methods like ViewDidAppear, viewWillAppear etc, no luck.</p> <p>I also tried accessing the refreshMe method I made in the dashBoard class through the tabController like this</p> <pre><code>[[[self.tabBarController viewControllers] objectAtIndex:0] refreshMe]; </code></pre> <p>But again no luck, this just causes my application to crash.</p> <p>I read through this guide</p> <p><a href="https://developer.apple.com/library/ios/#documentation/WindowsViews/Conceptual/ViewControllerPGforiOSLegacy/TabBarControllers/TabBarControllers.html" rel="nofollow">https://developer.apple.com/library/ios/#documentation/WindowsViews/Conceptual/ViewControllerPGforiOSLegacy/TabBarControllers/TabBarControllers.html</a></p> <p>on the apple website but it doesn't seem to cover how to refresh individual tab content. </p> <p>All I want is to have each individual tab refresh its content after the web call is made, and have spent ages trying to figure this out, but nothing is working.</p> <p>So would be very grateful if someone could show me what I am doing wrong?</p> <p>Thanx in advance....</p> <p>EDIT:</p> <p>Expand on what I have tried</p> <p>After discussion with Michael I realised you should never call loadView as against Apple guidelines. So I removed any references to LoadView. I have now placed a method in all the main ViewControllers called RefreshMe which sets up the views, images texts etc in the class. And this method is placed inside the ViewDidLoad. Now I want to be able to call these methods after a web call has taken place, so effectively refreshing the application.</p> <p>My viewDidLoad now looks like this in all my the main classes.</p> <pre><code>- (void) viewDidLoad { [super viewDidLoad]; [self refreshMe]; } </code></pre> <p>And then the refreshMe method contains the code which sets up the screen.</p> <p>The JSON data pulled from the web call will set up the content of each of the 5 tabs, so need them all to be refreshed after web call. </p> <p>I tried looping through the viewControllers and calling viewDidLoad, which should in turn call the refreshMe method which sets up the class, however nothing happens. Code I used was this</p> <pre><code>NSArray * tabBarViewControllers = [self.tabBarController viewControllers]; for(UIViewController * viewController in tabBarViewControllers) { [viewController viewDidLoad]; } </code></pre> <p>For the time being I have also included </p> <pre><code>NSLog(@"Method called"); </code></pre> <p>in the viewDidLoad of each class to test if it is being called. However the message is only being printed out when I first load the application or if I re-enter the application. This method should be called after I click the refresh button in the settings screen but it isn't and I have no idea why.</p> <p>Anyone have any idea why this is not working?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload