I am excuting the following line to add a Detail Viwe after my Table View is loaded:
if (!self.addView) {
self.addView = [[AddView alloc] initWithNibName:#"AddView" bundle:nil];
}
[self.navigationController pushViewController:self.addView animated:YES];
NSLog(#"I am done, now what");
Then I am presented with a screen of text boxes... I enter data and I save to a plist...
then to return Programatically, i perform the following line:
[self.navigationController popToRootViewControllerAnimated:NO];
My question is how to I refresh the tableview with the new record? I know it is in viewWillAppear method [self.tableview reloadData], but how do I trigger the viewWillAppear, as it is not gettin to that method after return?
any help would be appreciated.
Regards,
If you want to run reloadData every time your tableView is about to appear you can run [self.tableview reloadData] in viewWillAppear.
You probably want to put the [self.tableView reloadData] in the viewWillAppear method instead of the viewDidLoad method.
Related
I have a Tab Bar Controller. There are two tab. First one is for showing some data on Table View Controller on the basis of some calculation. And the second tab is for changing values of variables which are used for the calculation of first tab's data.
Now if I change value in second tab and back to first tab it does not update the calculated value in first tab. But it does when I run the app again.
I have gone through many solutions but not worked for me. I used
[self.tableView reloadData];
But not worked for me.
Please Help.
Use ViewWillAppear to refresh the viewController every time you click on the tab.
As in tabViewController ViewController is loaded only once.So ViewDidLoad Method is called only first time (As you say when your app restarts).
While viewWillAppear will be called every time you switch between the tabs.
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
//refresh the view controller
}
Please pass data between two ViewController and Put your code inside
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
}
It will work.
You are most likely calling your [self.tableView reloadData];
in viewDidLoad only. This is not called when you switch tabs since the views are already loaded. You can reload your tableView on viewWillAppear: like proposed by #Ved
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self.tableView reloadData];
}
otherwise, you can insert it in your setter. So every time your calculated value changes, your tableView will be reloaded.
New to Objective-C
Right now the data sends fine but the view controller I'm sending the data to (tableView) gets pushed by the navigation controller. I don't want this to happen because the view controller I'm sending the data to (tableView) is a subview of the view controller that sends the data.
PAWWallPostsTableViewController *tableView = [[PAWWallPostsTableViewController alloc]init];
tableView.data = #"TESTING";
NSLog(#"%#", tableView.data);
[self.navigationController pushViewController:tableView animated:YES];
simply do the reloading:
[self.yourTableView relaodData];
Here is some delegates of UITableViewController:
-reloadData
-reloadRowsAtIndexPaths:withRowAnimation:
-reloadSections:withRowAnimation:
-reloadSectionIndexTitles
See those for more info and determine what you need.
Hope this helps.. :)
If you are in PAWWallPostsTableViewController then its no need to create its object again and push it . you can try reloading PAWWallPostsTableViewController data :
[self.tableview relaodData];
It Depends on Which type of View Controller you want to Update as per the Data :
If it's UIViewController just put [self.view setNeedsDisplay];
If UITableViewController just put [self.tableview reloadData];
If UICollectionViewController just put [self.collecitonview reloadData];
I have just started working with tableViews, and I have 5 cells in a tableview in a viewController embedded in a navigationController. When a cell is pressed another view is pushed in. My problem is that the cell I press is selected but the selection doesn't go away. I have tried with this code:
- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
{
[self.tableView deselectRowAtIndexPath:indexPath animated:NO];
NewViewController *newViewController = [[NewViewController alloc] init];
newViewController.theTitle = [self.tableView cellForRowAtIndexPath:indexPath].textLabel.text;
[self.navigationController pushViewController: newViewController animated:YES];
}
The tableView is initialized in the viewDidLoad method. Still when I click a cell the new viewController is pushed in but the cell stays selected. What might be the issue here?
You've put your code in the didDeselectRowAtIndexPath - put it in the didSelectRowAtIndexPath. This is an easy mistake to make since didDeselect comes up in code completion before didSelect.
Summary :
You have tableview that is in a ViewController that is in a NavigationController
Use touch a cell
A new ViewController is push on the NavigationController Stack
User hit back and goes back to the screen where you have a tableView
That is what I understand from your question.
At this moment the cell in your tableView should still be selected in order for the user to have a reminder of the last action he as done, but you also want it to get unselected animated at the point ( the mail application is a good example of this behaviour).
So the best place to deselect the cell in your tableView is in - (void)viewDidAppear:(BOOL)animated method of the UIViewController that have the tableview inside it's view. By doing so you will let the user a chance to see the selection before it gently fade away like in mail.
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[self.tableView deselectRowAtIndexPath:[self.tableView indexPathForSelectedRow] animated:animated];
}
You can pass nil as argument of deselectRowAtIndexPath, tableView handles it gracefully.
Did you also implement tableView:didSelectRowAtIndexPath:? This method is called every time you tap a cell. So you should put your code there.
The method you are using, tableView:didDeselectRowAtIndexPath: is called whenever a cell is selected and you are tapping a different cell.
I think your problem is that you use wrong method. Change didDeselectRowAtIndexPath to didSelectRowAtIndexPath.
When my application launches, a table view is present and uses the information in two arrays (countdowns and countdown_info) to populate the cell title and description in the table view respectively.
A modal can be opened and used to create a new countdown. So far, it saves the data in a local file, closes, and then returns to the front controller, but the table is not updated with the new data.
How can I get the new information added to the table? The UITableView is named as *countdown_table
Thanks!
EDIT: The return code looks like this:
...Above Saves the File...
// The following generates a warning. ClockworkViewController is the main view controller.
//[[ClockworkViewController countdown_table] reloadData];
[[self parentViewController] dismissModalViewControllerAnimated:YES];
Load the newly added value to the array
Call [tableview reloadData] in your table view controller's viewWillAppear method.
Are you calling the [yourTableView reloadData] function? You should call this either when the modal view is saved, or when the table view becomes active again. This will then check all of the tableView's methods for number of rows, number of sections, etc, and reload the entire table.
You may explicitly call [table reloadData] when you dismiss the modal view
If you're using Interface Builder to perform your presentations/dismissals, you can very easily reload the ParentVC's tableView from the ModalVC's Exit Segue (transitioning back to the ParentVC, of course).
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:#"YourDismmssSegueID"]) {
ParentVC *vc = segue.destinationViewController;
// perform any needed data manipulation here
[vc.tableView reloadData];
}
}
I have a table View and a uibutton.
When i click on uibutton, it will display a model view control using presentModelviewcontroller method.
I have a text field and save button in the presentmodelview.
Please let me know how to reload table view when the user click's on presentmodelview save button
If you need the presentModalViewController to be removed and then the tableView to be reloaded then use this
[yourTableView reloadData];
on the viewWillAppear of the initial view.
First add the item to the array, then reload your table view.
Assuming you declared all properties needed including the array used by the data source.
#property(nonatomic, retain)NSMutableArray *modalArray;
The IBAction on Save button should include the following code:
//Add the item to the array
[self.modalArray addObject:[NSString stringWithFormat:#"%#",txtField.text]];
//Rest of your code, dismiss the modal view
Once dismissed, you need to reload the table view to show up the recent value saved on the modal view.
[self.yourTableView reloadData];
reloadData will call implicitly the data source method tableView:cellForRowAtIndexPath: which will loop the array again and so show you the new value.
In a nutshell,
YourViewControllerClass * vc = [[YourViewControllerClass alloc]init];
[self presentViewController:vc animated:NO completion:nil];
Hope this helps :)
when you want reload tableview please use below line
[self.tableView reloadData];