Question

I have an Xcode app that creates a tableview and then populates this with data from an sqlite database, this works perfectly and allows me to push data to a new view and delete etc,

This tableview is the first view loaded on a tab bar controller. The problem arises when i move to another view on the same controller, i.e. create an athlete, in this view i can add a new athlete to the database (which works fine) but when i go back to the tableview on the tab bar controller, the table is the same, i have to log out and log back in to see the change in the table,

I have tried [self.tableView reloadData] in the viewWillAppear function but this does nothing. I know that the function is getting called as i have placed an NSLog in their just for peace of mind.

I have found what i think may be the solution on here but i cant get it to work!

viewWillAppear, viewDidAppear not being called, not firing

i will post my code below and a screen shot of the storyboard as im convinced it is my poor way of setting up controllers that has caused this error. Any help would be much appreciated as i am now at the meltdown stage :D

-(void)viewWillAppear:(BOOL)animated {

//[super viewWillAppear:animated];

//[self.tabBarController viewWillAppear:animated];

[self.tableView reloadData];
NSLog(@"i just ran viewwillAppear");

}


- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {

athleteObject *athObj3 = [athletes objectAtIndex:indexPath.row];

athleteIdDelete = athObj3.athId;

[self openDatabase];

[self deleteAthleteFromDataBase];

[athletes removeObjectAtIndex:indexPath.row];

[tableView reloadData];

}

reloadData works in my commitEditing function (this updates the tableview when i delete an entry via a swipe)

any help would be much appreciated, il post the screen shot below.

(cant figure out how to load a screenshot if its even possible)

Was it helpful?

Solution

It looks like athletes (a NSMutableArray I assume) is not being updated in viewWillAppear. Have you tried running the selector that populates the array from the database before calling reloadData?

Hope that helps!

OTHER TIPS

I'm assuming you're setting the number of rows/sections in your code based on how many objects are returned from a database.

Set a breakpoint at this method, and get the count each time the compiler breaks. You are probably not getting any objects from the database, and therefore the compiler never runs the rest of the table view dataSource methods.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top