Piscean
Piscean

Reputation: 3079

How can i refresh a view every time when a tab bar item is clicked?

I am making an application with TabBar. But TabBarController is not RootViewController. In the Tab Bar there are 4 tabs. One of those tabs is history which is linked with a table view which shows history. I want to refresh that view every time when i click that so that i can get updated tableview. How can i do that? Thanks in advance.

Upvotes: 11

Views: 16152

Answers (4)

user4302419
user4302419

Reputation:

instead of using (void)ViewDidLoad use viewWillAppear:(BOOL)animated

- (void) viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    //your code 
}

Upvotes: 1

AHSAN NAZIR RAJA
AHSAN NAZIR RAJA

Reputation: 166

-(void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:YES];
    if ([Globals sharedInstance].isFromFindSimiler)
    {
        [self.view addSubview:_findSimilerView];
        [_historyTableView setFrame:CGRectMake(0, 85, 320, 490)];

    }
    else
    {

    [self history_webservice];
    }
}

I have achieved this. In this case, whenever user tabs on History screen I call web service for history and update tableview.

Upvotes: 1

rckoenes
rckoenes

Reputation: 69499

use - (void) viewWillAppear:(BOOL)animated to update any content in your view.

- (void) viewWillAppear:(BOOL)animated {
   [super viewWillAppear:animated];
   // You code here to update the view.
}

This method will be called every time the view is about to be displayed.

Upvotes: 8

bitmapdata.com
bitmapdata.com

Reputation: 9600

below code added plz ^^

If you change a tabBarIndex, At the same time -(void)viewWillAppear called.

-(void)viewWillAppear:(BOOL)animated
{
    // force the tableview to load
    [tableView reloadData];
}

refer a Apple Sample Code: that is amazing great tutorial for you about UITabBarController http://developer.apple.com/library/ios/#samplecode/TheElements/Introduction/Intro.html

Apple Sample Code is no added [super viewWillAppear:animated];

Upvotes: 1

Related Questions