How to refresh/reload a UITableView - ios

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];

Related

How do I update view controller instead of pushing view controller when sending data?

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];

UITableView Delegate

I have a table view cell with a "Show More" button. On clicking the button I want the delegate
-tableView:didSelectRowAtIndexPath: to get called ?
Can someone tell me the difference between the following 2 statements:
[self tableView:self.tableView didSelectRowAtIndexPath:indexPath];
and
[[self.tableView delegate] tableView:self.tableView didSelectRowAtIndexPath:indexPath];
There shouldn't be any difference between those two statements, assuming that self is the delegate of the table view, and you have a property called tableView in your controller that points to the table view (connected to the table view in IB if it's an outlet, or assigned to the table view in code if you created the table view there).

Screen refresh in Tableview after call to DetailView Controoler

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.

Force tableView reloadData from Modal Dismissal?

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];
}
}

Make UITableView selection before view appears

I'm building a detail view for a UITableView. The detail view contains a UITableView which has two rows, and I want the first one to be selected when the detail view is opened. I have tried to use the method [selectRowAtIndexPath:animated:scrollPosition] in [viewWillAppear]:
- (void) viewWillAppear:(BOOL)animated {
[[self tableView] selectRowAtIndexPath:[NSIndexPath indexPathForRow:kStartDateRow inSection:kSection]
animated:NO
scrollPosition:UITableViewScrollPositionNone];
}
However, the selection is not affected by this, and using it in [viewDidAppear] means the selection changes once the view has moved into place. How can I make the selection before the detail view appears on screen?
You can see an example of the behaviour I want in the Settings app. Go to General > Date & Time > Set Date & Time.
You don't mention any error but try doing [[self tableView] reloadData] before the selectRowAtIndexPath line.

Resources