1

I'm creating the UITableView datasource array using this code:

-(void) viewWillAppear:(BOOL)animated
{
    // IBOutlet of tableview is 'editMsgTableView'
    editMsgTableView.dataSource=nil; 
    editMsgTableView.delegate=nil;

    menuMessageArray = [[NSMutableArray alloc] init];
    editMainMenuMsgArray = [[NSMutableArray alloc] init];
    menuMessageArray = [DBManager fetchmenu:0 noOfRows:32];

    for(int i=0; i< [menuMessageArray count]; i++)
    {
        NSMutableDictionary *menuMsgListDic = [[NSMutableDictionary alloc] init];
        menuMsgListDic = [menuMessageArray objectAtIndex:i];
        [editMainMenuMsgArray addObject:menuMsgListDic];  
    }

    editMsgTableView.dataSource=self;
    editMsgTableView.delegate=self;
    [editMsgTableView reloadData];
}

But it works for the first time. But whenever I do some tableView editing stuff or comes from another view controller,after that if viewWillAppearis called then reloadData is not working. I also tried:

dispatch_sync(dispatch_get_main_queue(), ^{
    [editMsgTableView reloadData];
});

but not working. Please help me out.

9
  • 1
    maybe your reload is called but noting is changed. Do the delegate methods of tableview get called? Commented Feb 4, 2015 at 6:18
  • 1
    is your data source array get updated data? check that too. Commented Feb 4, 2015 at 6:19
  • First of all, do you really want to populate the contents of your table everytime your view will appear? Have you debugged if numberOfSectionsInTableView get called? Commented Feb 4, 2015 at 6:19
  • Why you are removing and setting datasource & delegate of editMsgTableView each time in viewWillAppear. Instead set delegate and datasource in viewDidLoad. Use dealloc method for releasing. Commented Feb 4, 2015 at 6:22
  • @FawadMasud : Yes, everything is working fine. Commented Feb 4, 2015 at 6:29

4 Answers 4

3

When editing begins call [tableView startUpading]; and when editing is done, call [tableView stopUpdating]; then [tableView reloadData];.

Sign up to request clarification or add additional context in comments.

2 Comments

this can easily go in comment
@tod not enough repo :)
0

Try ,

dispatch_async(dispatch_get_main_queue(), ^{
    [editMsgTableView reloadData];
});

Comments

0

are you giving to that viewController the tableViewDelegates correctly? :

@interface theNameOfTheViewController : UIViewController <UITableViewDelegate, UITableViewDataSource> in the .h file?

i suggest not to do this:
editMsgTableView.dataSource=nil; editMsgTableView.delegate=nil; editMsgTableView.dataSource=self; editMsgTableView.delegate=self;

just this:

[self.editMsgTableView reloadData];

be sure that all the delegate methods are called when you use reloadData (put a breakpoint in every delegate method that should be used to reload the Data of the table when you make a change or the view Appears), remember that reloadData method, calls all delegate methods (if you´re giving to the view controller correctly the delegate as I said before) of the tableViewController. If nothing of this helps you, tell me.

Comments

0

I am assuming that you are navigating the view from one view to another view, then you should call [tableView reloadData] on ViewDidLoad. This is because of the view life cycle - when you are coming back from one view and your tableView data source is updated, the view life cycle will be like this:

  1. viewDidLoad
  2. tableViewDelegateMethods
  3. viewDidAppear

So when you update tableView's data source object and call reloadData during viewDidLoad will resolve the issue.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.