reloadData method not called from another class.

Discussion in 'iOS Programming' started by Amit Jain, Jul 21, 2009.

  1. Amit Jain macrumors member

    Joined:
    Apr 9, 2007
    #1
    Hi All,

    I will directly start from an ex:
    I have two classes A and B, both are derived from UITableViewController.

    I have also added them into navigation controller so there is navigation going on from A to B. These both classes use database for showing data into the table. Now in B View I delete a row from the DB and A view displays the row count of that DB table. Now what I am doing is on the BACK button of the navigation I want to I am calling this method
    TRY 1:
    Code:
    //in class B
    -(IBAction)backBtnPressed
    {
    [ObjA.tbleView reloadData];
    [self.navigationController popViewControllerAnitmated:YES]; 
    }
    
    on its action. The problem is this method does not reload the data of View A. i.e., it doesn't call the tbleView's delegate methods like cellForIndexPath...etc.
    Then I thought that may the reloadData shud be called from the same class so did this
    TRY 2:
    Code:
    //in class B
    -(IBAction)backBtnPressed
    {
    [ObjA.tbleView myReloadData];
    [self.navigationController popViewControllerAnitmated:YES]; 
    }
    //Class A
    -(void)myReloadData
    {
    [self.tbleView reloadData];
    }
    
    It comes into this method but still doesn't call the tableView delegate methods. Please let me know why I am not able to do this silly thing :(.
    Regards..
    Amit
     
  2. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #2
    If these view controllers are really derived from UITableViewController then their property is self.tableView, not self.tbleView. Not sure why there's a discrepancy.

    What is the value of the property that you're using? self.tbleView. Is it nil or not?

    The code you show should work.

    You can just as easily do this by calling reloadData from viewWillAppear or viewDidAppear.
     
  3. Amit Jain thread starter macrumors member

    Joined:
    Apr 9, 2007
    #3
    I would like to describe the calling of viewControllers in my code:
    I have a rootViewController (added in mainWindow.xib) the viewWillAppear method of this class is called perfectly. I will give you the caling hiearchy of methods :
    applicationDidFinishLaunching-->[rootViewController viewdidload]-->in viewDidLoad of rootView i have loaded another viewController that has tabbar on it having 4 classes(A,B,C & D). So by default 1st class (i.e A ) viewDidLoad is called. Class A has a tableView control and added as navigation control so that clicking on any rows navigates to another classes viewControllers (A-->X-->Y..). The problem here is only rootviews viewWillAppear method is called rest of the classes (A or X or Y..) viewWillApperar method is not called.
    I hope you are not confused ). Please help i am stuck from many days in this problem .
     

Share This Page