NSFetchedResultsController saving data but UITableView not configuring cell - ios

When returning from a ViewController where I add and save an NSManagedObject, the TableView inserts a blank cell where the new cell should be. If I back out from the tableview screen and go back, it reloads and configures everything properly.
So what I know from this is that the data is being properly saved to the store, I know the FRC delegate operations are all being called (.Insert, for instance), and I actually can see via breakpoints that my "configureCell" method is being called and is passing back a fully configured cell. The tableview is just putting in a blank one instead.
I can post code if you'd like, but I was just curious if this description rang any bells for anyone? I've been researching this problem off and on for weeks but haven't really found anything similar.
For troubleshooting purposes I:
took my custom UITableViewCell out of the mix and just had the tableview configure a generic cell... didn't help.
created a stripped-down version of the app flow in another project, including core data, FRC, custom tableview cell, etc... this actually DOESN'T display the same behavior. I've compared the two projects side by side and can't determine any meaningful difference (other than the data itself that's being displayed).
I've even gone so far as to insert a delay between the context.save() operation and dismissing the VC where I create the object, just to see if it's some sort of race condition between when the object is created and when the table configures the cell. Needless to say, that did nothing.
Is this a bug anyone else has encountered? Anyone seen this behavior before?
Thanks in advance, sorry for the wall but this is something that Google, various subreddits, and so far StackOverflow has not been able to help me with.

Well after rephrasing my question I found this from back in May.
New table view cell shows as a blank cell
No solution there, but I reached out to him via twitter and his suggestion worked. Switching my size class back to any/any seems to have solved the problem, which means this might be an autolayout bug. It needs more testing but I think I've done everything that would demonstrate the issue and I think it's resolved.

Related

Unable to identify operative event or method in XCode

I need help identifying what piece of code is causing a bug in my app but having a hard time working it out.
So, my app is designed to display a detail screen for any row that is selected in the master table.
I have recently updated my app to use an NSFetchResultsController. The results are what I would expect except for one odd behaviour.
The new behaviour happens when I select a row in the master table, prior to the segue to the detail screen.
The table populates with all the data I would expect. But, on clicking any row in the table (other than the first one), each field in the row is set to the default values that appear in the storyboard.
The segue to the detail screen displays the expected details and the underlying database table is also correct.
I have a segue outlet action on the cell but no other method.
Despite placing breakpoints at various points in the code, I cannot identify which code section is triggering the setting of the row to the storyboard defaults.
I'd appreciate any steer that would help me work this out.
I posted my question as relative newbie to xCode. I've now discovered the profiling tools built into xCode and have been able to identify what's happening in my code with more confidence.

Preload tableView cells and prevent reloading

I already found entries with that topic on this page and also a website that provides a tutorial for that problem. But nothing worked very well.
The tutorial sad I should double the height of my tableView so cells loaded earlier, but with a higher tableView I never reached the last cells.
My problem is, I use a tableView to display my apps mainpage. This mainPage shows every time a topic and if its necessary for that topic it shows for example a cell with a map, one with pictures and sometimes not. Problem now, if I trying to scroll to my view its always lagging because it loads a map or this pictures. And scrolling back again because the loaded cells already deleted. I used a tableView because of the possibility to switch celltypes(mapCell, pictureCell, textCell) on and off.
I understand this feature, because of memory issues but in my case its not that much and it would be better if all my cells be preloaded and stay in memory until I change the topic.
Is there a swifty way to told my tableView to have this behavior?
Thanks a lot and nice greetings
I would suggest a different approach. Set up your table view controller to install placeholder images in your cells, trigger an async download that you cache to disk, and then update the cell with it's downloaded content if it's still visible when the download is finished.
There are various third party frameworks that do all this housekeeping for you.
Declare a cell array.
Follow these steps whenever change in your topic.
Clear you array
Create and configure all cells add to your array.
Return these cells to datasource methods using row index. Don't use tableview dequeue method here.

UIScrollView multiple page confusion

So I have an existing app I'm working on for a friend...
and let's say I double click on animals_real and I get this screen...
Basically all I want to do is create a back button back to the home page on the animals_real page and all the other ones like it(body_parts_real, cleaning_real, etc.) but for whatever reason I can't find the xib file or the code for it and I'm not entirely sure what file it would be in. Also, since I am fairly new I'm not entirely sure how to implement the back button. Any help is greatly appreciated.
----------------------------------EDIT 1------------------------------------------
The main page works under ViewControllerForIphone.xib and the settings page is under SettingViewControllerIphone.xib. This led me to believe that the other pages would be under the SubPECSViewController_iPhone.xib. However, if I go in and edit that it doesn't change anything when I run the simulator. So, basically I have been trying to understand UIScrollView better and how it works but I am kind of just stuck.
Welcome to iOS. Other commenters will point out that you should start here at the UICollectionViewDelegate Reference (which you can also get to through Xcode (shift+command+0)
Basically, a uicollection view populates itself based on some array of data.Look here to see what's going on
(void)insertItemsAtIndexPaths:(NSArray *)indexPaths
When you tap on animals, this method is called:
– collectionView:didSelectItemAtIndexPath:
Some logic happens here, and I'm presuming you load the collectionview from yet another array.
To solve your original problem of a "back button," you might simply want to reload the viewcontroller's original datasource or possibly "pop" back up the navigation stack. Again, without seeing at least part of the code, there's very little we can do except speculate :)

UITableview cell reinitializing every time in iOS 7

All,
I hope most of you know that with ios7 there is not need to do a null check for tableview reuse
if (cell == nil) {
But unfortunately, because of that the cells are always reinitialized, as we put the code in the same method for initializing values. The problem is only with text fields inside the tableview though.
Let me explain the scenario. I have a table view with multiple rows, and some rows contain multiple text boxes. I populate the textboxes with data from server when the page is loaded. Since the cells are always re-initialized as i explained above, whatever I enter in the field goes away and the server data is re populated once i scroll down and come back to the initial stage. This is because the populating the data code is also in the same place. After fetching a reusable cell it populates the data.
Previously till ios6, we used if(cell==nil) and hence we loaded server data inside the cell and when reusing the cell, this piece of code will never be called.
I have other dirty solutions, but would like to know if someone else has a graceful way of dealing this. Please help.
You just don't store any data in the table view cell but in the model that fills the table cell. This is always the way it should be done.
Looking from the MVC standpoint than the UITableViewCell is a view. Since it is reused by iOS you should use a model to the view.
Yes, this is the expected behavior of UITableView. For performance reasons, cells are reused. Thus, it is your responsibility to populate the views in a Table View Cell every time tableView:cellForRowAtIndexPath: is called.
The thing I don't understand from your question - are you making a network call every single time a cell comes into view? If so, cache the results somewhere. Or, if it's a small amount of data, consider just doing it all in one shot at the beginning (still need to be asynchronous though).
One thing I see a lot of developers do is move a lot of code into UITableViewCell subclasses, which sounds like a good idea because it's modular, but makes solutions for problems like this more difficult. Have the Table View Data Source manage the network calls.
If you need some inspiration, look at Apple's LazyTableImages sample.

UITableView Core Data reordering (next)

UITableView Core Data reordering
I'm having troubles with the solution above. If I do updates one by one (ie one move or one delete at a time) it works when back to noedit mode. But with more updates I get application crash. (I'm using a fetchcontroller)
Could someone try this from a tableview not populated :
- create 3 rows
- hit edit mode and move 1st cell to 3rd position, still in edit mode delete the second cell.
- back to noedit mode it crash for me
Besides this I'm trying to make it work in grouped style and with several sections, where you can move cells to any section. Is someone knows an application doing this correctly ?
Thank you
Well after days trying different solutions it seems I finally get what I wanted.
In addition to Ryan Ferretti solution I had to put a flag to bypass tableview updates when commiting moved modifications on CoreData, to get it work with nsfetchedresultcontroller delegate.
It is describe on Apple documentation, see User-Driven Updates : http://developer.apple.com/library/ios/#documentation/CoreData/Reference/NSFetchedResultsControllerDelegate_Protocol/Reference/Reference.html
I now get a tableview grouped style and can move rows from any section to another one, sorted like I want.
So don't forget this flag. :-)

Resources