tableView not updating after adding Core Data object - iphone

Given this Core Data Model: Photographer <-->>Photos.
After adding a Photographer via a Modal View, the tableView of Photographers updates accordingly.
The problem is, that it doesn't do the same for Photos. I can add a Photo via a Modal View, and the tableView of Photos for that particular Photographer does not update immediately. Once I navigate back to the tableView of Photographers and select the same Photographer again, it updates as expected.
How can I get the tableView of Photos to update as soon as the Modal View(where the user added the object) gets dismissed?

Where modal view dismiss try to use:
[tableView reloadData];

Try
[tableview reload];
method after getting new data.

Check your error variable if it contains an error.
You directly assign the result of -executeFetchRequest:error: to an ivar (photographerPhotosArray). This either leaks or causes an immediate release.
Consider switching to NSFetchedResultsController since it helps you a lot.

Check your array first is it fill or empty? try with NSLog and check it. if it exist then reload your table

Related

how to update uitableview in UIViewController

I've UItableView in UIViewController and database connected to UItableVIew it loads data from sqlite3 database but its not Showing new content when i add new content to database until i relaunch the application. I tried below code
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self.LengthTableFrom reloadData];
}
when you add new content at that after that get all data again and also add this line after get all data
[self.LengthTableFrom reloadData]
i hope it will work fine..
:)
I think when you are adding or editing your data to database.
And in viewController where tableView exist
In viewDidLoad you are fetching data from database & saving into array. Reloading list in viewWillAppear. For fist time it works fine, after when you add new content to your database your array for tableView will not be having new content.
For testing you can have your data fetching from database in your viewWillAppear view controller, to check it works fine.
In real time you have to add the new content to database get the ref id, and add the new content with ref id to your array for tableView.
It's simply mean that you are not calling the [self.LengthTableFrom reloadData] method properly.
You should place this code [self.LengthTableFrom reloadData] just below the code where you fetching the database content .
i hope it'll work fine.

Reloading a table's data

I have 5 view controllers, which are in a navigation controller hierarchy. When I reach my last view controller, there's a button that lets me go back to the "Home" view controller (named CardWalletViewController) which is a table view controller. Here's the method I have in my last VC (PointsResultsVC)
- (IBAction)homePressed:(id)sender {
NSArray *VCs = [self.navigationController viewControllers];
[self.navigationController popToViewController:[VCs objectAtIndex:0] animated:YES];
}
CardWalletVC's cells is being filled up by values coming from the saved instances of a Card in NSUserDefaults and it works fine.
Now, what I want is to update the value in my CardWalletViewController, which is the points of a card coming from my PointsResultsVC. Note that this points is saved in NSUserDefaults.
Upon the process of trying to update of the value shown in my CardWalletVC, I placed [self.tableView reloadData]; inside -viewDidLoad, -viewWillAppear, and -viewDidAppear of the said class. I tried placing it one by one in each of this methods, yet it doesn't seem to work.
Advice Please.
EDIT: problem solved
This one served as my guide Save data from one tab and reloadData in another tab.
And as I have discovered, -viewDidLoad of a certain class will only be called once, all throughout runtime of app. Whereas -viewWillAppear, it will be called every time the view appears.
So, I just moved the way I am loading the values saved in NSUserDefaults from -viewDidLoad to -viewWillAppear. Also, inside -viewWillAppear I placed the [self.tableView reloadData]. Then there, problem solved.
There's a lot of things that could be going wrong so you'll need to provide more info to narrow it down.
First of all, viewDidLoad will not be called so you can remove it from here. Both viewWillAppear and viewDidAppear will be called, so you only need it one of these 2 methods.
Next, you need to determine what the actual issue is.
1 - is self.tableView a proper reference to the table? Are you properly maintaining the reference?
2 - is the table actually reloading but using the old data, or is it not reloading at all? You can log the willDisplayCell method to see what is going on when the view appears.
With that info, the root cause can be narrowed down to a solvable problem.

Deleting rows UItableview iphone using userdefaults

I need your help, maybe its something silly but I can't find the error.
I have a table view and an add button, when its clicked I show a modal view with a little form, when save button is pressed I send the data to the TableView controller to show it, also I'm using NSUserDefaults to save this data in an array.
My problem comes when, for example, I add 2 new rows and delete 1 of them, then when I add another, it shows the last row I delete instead of showing the one I just add.
I'm doing the saving and reading this way:
in viewDidAppear I read the NSUserDefaults and get the data if exist.
in the method that catches the data from the ModalView I save to userdefaults.
in commitEditing method I read userdefaults and then delete the row from the array and from the table and then save this change in userdefaults.
I don't know what I doing wrong, Can anybody help me with this?
Use [self.tableView reloadData]; in the viewWillAppear of that class. You can also reference that class in another view controller, create an object for it and call [classObject.tableView reloadData];
Always remember to reload the tableView after an add operation or a delete operation.
Don’t use NSUserDefaults to act as the direct datasource of a table. Store it in an intermediate model. It’ll be a LOT easier to debug that way.
If you’re having trouble keeping your model synced with the user defaults, call [[NSUserDefaults standardUserDefaults] synchronize] whenever you alter them.
Also, make sure you’re not making some mistakes in your table cell reuse. You might be seeing old data if you have a customer UITableViewCell class and you’re not correctly implementing -prepareForReuse.

can I reload UITableViewController with out reapearing or reloading the table

I am developing an app in which I have to delete the contacts from table ,problem is that when i delete one contact ,I have switch from one view to another then I can see the changing b/c i put the reload method in viewAppear any suggestion?
In general you should avoid to use reloadData to refresh the content of a UITableView, you should only do it if you can't avoid it (ie you replace everything in your table) or the user won't see it (ie in viewWillAppear).
I would suggest to use insertRowsAtIndexPaths:withRowAnimation: to insert single rows and deleteRowsAtIndexPaths:withRowAnimation: to remove rows.
So you get the indexPath of the row when you delete a contact and call [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:deletedIndexPath] withRowAnimation:UITableViewRowAnimationFade]
Those details make the difference between a app and a good app.
you can call [self.tableView reloadData]; to reload the table view by staying on the current view.
You can immediately reload table after deleting the contact !
Just call [self.tableView reloadData] in the UITableViewController after the data has been modified. This will update the table view to and reflect the new state of the data.

How to "refresh" UIView

I have data being refreshed in a modalViewController and when that data gets refreshed, the parent controller needs to refresh its data as well. I tried doing a [tableView reloadData]; but it didn't work properly since the actual array values aren't being refreshed. Is there a way for me to reload a controller without the user seeing any animation?
Thanks for any help!
Are you refreshing the data off the main thread? If so, you need to call the reloadData method using the following method:
- (void)performSelectorOnMainThread:(SEL)aSelector withObject:(id)arg waitUntilDone:(BOOL)wait
So for a tableView it would be something like:
[tableView performSelectorOnMainThread:#selector(reloadData) withObject:nil waitUntilDone:NO];
The underlying view can get released while the modal view is showing, so you shouldn't try to modify it directly. Instead, you can use the viewWillAppear: method on the main view controller to make any necessary updates.
I'm not sure what you mean that "the actual array values aren't being refreshed". How the two view controllers exchange data depends a lot on what you are trying to accomplish. If the modal view is only used in one place, the main controller can access its properties directly. Or maybe you want a dedicated class to hold the state... Again, depends on the context.