Tableview not reloading after data change : IOS 5 - tableview

I need help in following scenario.
I am building an app that displays tableview. If the user tap an entry it goes to the detailed screen. In the detail screen, I have a button to delete this entry. It deletes the entry from the data source and dismiss the modal.
But after dismissing the modal, table view data is not refreshing.
If I go back to parent view controller and then again come back to child screen, it refreshes the count.
I read few similar posts and found the following solution.
[tableview reloadData];
Or
[self.tableView reloadData];
In - (void)viewDidAppear:(BOOL)animated of child screen.
But its not refreshing the table view.
Please help.

For completeness, the full implementation would be:
- (void)viewWillAppear:(BOOL)animated
{
// Do stuff like reload the tableview data...
[self.tableView reloadData];
}
If it's not working you have a problem elsewhere in your code.

If the tableview is in the parent viewcontroller, I suggest that placing reloadData: method at viewWillAppear: of the parent.
(void)viewWillAppear:(BOOL)animated
{
[self.tableView reloadData];
}
I'm sure that the method will be called when the detailed viewcontroller dismissed.

Go through this code:
- (void)viewWillAppear:(BOOL)animated
{
[self.tableView reloadData];
}

Related

self.tableView reloadData not working in viewWillAppear

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)
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!
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.

Update a UITableview from a different view when both views visible at once

Looking at my iPad app, I have several containerviews. Containerviews enable me to show all four iphone views on a single iPad screen simultaneously. One view, called TrackingViewController, has a UITableView on it (called table) that I want to refresh from a button on a second view controller (MainViewController) which is also visible on the same iPad screen. I call the code
TrackingViewController *trackView = [[TrackingViewController alloc] init];
[trackView.view setNeedsDisplay];
[trackView.table reloadData];
at the end of the IBAction for the button in MainViewController, the data transfers perfectly, but the table itself on TrackingViewController does not visually update to show this data.
If I then manually initiate a completely different modal view controller and dismiss it on TrackingViewController when the app is running on iPad then the data shows up. How do I make the view or data on TrackingViewController automatically update visually when the button is pressed on MainViewController?
iPad Simulator may help.
I also dont understand your question..
The only thing I see is, you want to update two UITableViews but in your code you are only reloading Data of one TableView?!?
[trackView.table reloadData];
[otherTable reloadData];
But I realy dont understand your question....
If your other TableView is in another class, just try something like this...
In TrackingViewController.h:
- (void)refreshMyTable;
In TrackingViewController.m:
- (void)refreshMyTable{
[table reloadData];
}
In your MainViewController.m Action, that should refreshes both Tables:
- (IBAction)theRefreshingAction{
TrackingViewController *trackView = [[TrackingViewController alloc] init];
[trackView refreshMyTable]; //This refreshes Table in trackView
[mainViewTable reloadData]; //This in MainView
}
Ended up using NSNotificationCenter by utilizing the following post:
Calling a function from a different view controller for iphone
In my case, calling a function that only included [table reloadData]; wouldn't work, but calling my performFetch function did (which also called [table reloadData]; at the end of it).

Xcode reload complete UITableViewController

I have a tableviewcontroller with some sections which can be collapsed and expanded.
it is also possible to add new sections to my tableview.
But newly added sections are only visible after closing and reopening the tableview.
Somehow, I need to reload the whole tableview after adding a section.
[tableview reloadData] doesnt work.
So how can I manually reload the complete tableview without closing and reopening
the window? (or at least the user shouldn't notice a close and re-open operation).
I think this should work :
- (IBAction)refreshButton: (id)sender {
[self.tableView reloadData];
}
or it might be this
- (IBAction)refreshButton: (id)sender {
[self reloadTableData];
}
Hope it works!

UIImageView shifted when I click my back button

I've got a small project with two UIImageView-based nib files.
When the main view loads, it looks correct.
To switch between views, I'm using code like this (for example, this is to go to second view)
-(IBAction) secondClicked:(id)sender {
SecondViewController *second = [[SecondViewController alloc] initWithNibName:nil bundle:nil];
[self presentModalViewController:main animated:NO];
[second release];
}
When the new view is shown, it's shifted sideways about 10% of screen. Using similar code to go back to main results in the main view being shown similarly offset.
I'm in landscape mode, if that makes a difference.
How can I display the views so they're correctly aligned?
Ok it makes sense now that I looked more carefully. Why are you presening a view controller modally when you wish to go back? How did you showed this viewController initially? If it was through a navigation controller you should pop the view
[self.navigationController popViewControllerAnimated:YES];
If it was presented modally you should just dismiss it!
[self dismissViewControllerAnimated:YES];

UINavigationController back button issue

My Application have navigation controller and table views. When the back button is clicked and the view is popped out from controller stack, i noticed that the table events are not executed (eg: cellForRowIndexPath). Is there anyway that these events are execueted when view is popped out.
This is the code i use for pushing the view into controller stack.
MyViewController *obj = [[MyViewController alloc] initWithNibName:#"MyViewController" bundle:nil];
[self.navigationController pushViewController:obj animated:YES];
[obj release];
Regards
Sandy
You can use the ViewWillAppear and ViewWillDisappear methods.
what you want to do is put a call to
[theTable reloadData];
which initiates all of the calls that you wanted.
This call should be placed where you want the table to reload - either on appear or disappear.
Good Luck !

Resources