My Existing TableViewController is crashing on Xcode 11 beta1 - ios

I have developed a UITableViewController screen. It's working fine on Xcode 10.2 but. When I run on Xcode 11 beta 1 it's crashing like below.
I didn't find what was happening.
In ViewDidLoad
override func viewDidLoad() {
super.viewDidLoad()
tableView.tableFooterView = UIView()
plateNoPrefix.becomeFirstResponder() // static cell textfield in tableViewcell
}
Exception… Attempted to access the table view's visibleCells while they were in the process of being updated, which is not allowed

I have faced the same issue when providing support for iOS 13.
This is a new exception in iOS 13 that UITableView will raise in order
to prevent and proactively alert you of a situation that would
previously cause undefined behaviour and a variety of strange,
seemingly unrelated, and hard-to-debug issues (including crashes).
What is happening here is that UITableView is in the middle of asking
its dataSource to return a cell for each visible row and is
configuring the properties of the returned cells so they can be
displayed. And in the middle of this updating -- most likely inside a
callback from the table view itself about a specific row such as
tableView(_:cellForRowAt:) tableView(_:canEditRowAt:), etc -- your
code is asking the table view to return the visible cells. This is
obviously problematic, because UITableView is right in the middle of
preparing those cells, so it cannot possibly return a meaningful
answer.
The fix for this is to look at where you are calling visibleCells in
the backtrace when this exception is raised, and then do one of two
things:
Option 1:
Move the usage of visibleCells to a better place, so that you aren't
asking for the visibleCells from someplace that is called during the
process of creating/configuring/updating those same cells. A great
place to ask for the visible cells is after the table view lays out,
so for example if the table view is the view of a view controller you
can use viewDidLayoutSubviews(), or in a subclass of UITableView do it
after calling super.layoutSubviews().
Option 2:
Depending on what you're actually trying to do, you might be able to
skip using visible cells altogether. For example, you might be able to
leverage the callbacks tableView(_:willDisplay:forRowAt:) and
tableView(_:didEndDisplaying:forRowAt:) to track when cells are
visible instead.
If you are hitting this exception and you think you are requesting the
visible cells from a location that should be valid/allowed, please
share the backtrace when you hit this exception and details about what
you're trying to do.
Update:
I am sure but plateNoPrefix.becomeFirstResponder() causing the crash. As of now, you can check by pasting this code in viewDidAppear method
OR
Execute this code after delay (Worked for me)
DispatchQueue.main.asyncAfter(deadline: .now()+0.1) {
// Your code
}
For details clerification you can refer Apple Developer Forum

This is a new exception in iOS 13 that UITableView will raise in order to prevent and proactively alert you of a situation that would previously cause undefined behavior and a variety of strange, seemingly unrelated, and hard-to-debug issues
Please have a look at Apple Developer Forum

Related

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.

NSFetchedResultsController saving data but UITableView not configuring cell

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.

iOS infinite scroll items disapearing (sometimes)

This is a very rare occurring bug from hell,
I have an infinite scroll controller that displays products, 2 in each row. Rarely, something affects the controller and causes items to vanish, when I tap the empty area where the item should be, it works as expected and directs the user to the item details controller. When I back out back to the list, sometimes the cell shows its content, and others get hidden.
Sometimes it just a couple of items missing, sometimes there are so many missing items that makes the list appear empty, like only 1 or 2 cells are visible per screen height.
An even stranger situation is, when I scroll really fast to the end and stretch the screen really fast out of the visible area, and there are no more items to load, the visible items can jump from left to right.
Please see these two videos.
https://www.dropbox.com/s/jibflcouz1ena8n/missingProductImages.mov?dl=0
https://www.dropbox.com/s/uz13fzorypnp38t/again.mov?dl=0
I could send code but I didn't want to clutter this place with full length code, let me know if you want to see a specific section of the code please. Maybe someone could have an idea of what might be going on by looking at the vids.
What's probably going on here is a state problem with your collection view cells. The code assigning model values to the cell's views would be of use here. But absent any actual information, the first thing to review would be the cell's prepareForReuse implementation:
Does it call super?
Does it clear out all current values?
Does it cancel any pending asynchronous operations?
Are fetches and cancellations correctly matched?
Next, check if there's any essential configuration in the cell's init/initWithCoder methods -- those are only called on first creation, not on reuse.
Those are the normal pitfalls of UICollectionView cell handling. If they don't suggest the problem, please post the cell code.
It looks like your cells are not being reused correctly.
Can you check that you have set the same reuseIdentifier for your cell in Interface Builder that you are assigning in your code?
Update: Attached image to show where to set the identifier in the storyboard/xib
Update: added layout solution
Another problem could be due to the layout bounds of your collectionViewCell. When you load your cells they bounds are not calculated until they have been added to your collectionView and rendered. This can cause the elements in your cell to layout with the wrong values. This happens commonly with async image frameworks as they cache a resized version of the image for performance. When you cell loads, the cached image is loaded at the wrong the wrong size.
Add the following code to your collectionViewCell:
- (void)setBounds:(CGRect)bounds {
[super setBounds:bounds];
self.contentView.frame = bounds;
[self setHighlighted:NO];
}

UICollectionView stops loading cells after moveItemAtIndexPath:toIndexPath:

I have a UICollectionView with UICollectionViewFlowLayout which contains many items. I want to reorder a cell due to the user input.
[self.collectionView moveItemAtIndexPath:indexPath toIndexPath:newIndexPath];
After execution of this code, the collection view doesn't update it's contents when scrolling. It doesn't show next cells. It doesn't even call cellForItemAtIndexPath: but it's content size is correct (the layout "updates" it's state).
Therefore we can only see the cells which were distributed on the collection view before the reorder.
Any clues what might be the issue ? Are there any known workarounds for this issue? The app is iOS 8 only and the collection view is used with the UICollectionViewFlowLayout.
EDIT: When I call [self.collectionView reloadData]; the datasource is not even asked for anything, too.
The issue was with the UICollectionViewCell. High level description is that the cell is sent a method actionForKey from my code during the move animation. It caused the cell to stay in internal being animated state. I couldn't find reasonable workaround and refactored some bits in order to avoid actionForKey call. Now everything works as expected.

The table view custom cell are not dealloc/release when I called the UITableView method "reloadRowsAtIndexPaths"x

I have create custom cell in table view. Each cell is different in terms of UI. I have craetd three cell and identifier for each cell is different. The custom table view cell are not released when I called the method "reloadRowsAtIndexPaths". Here is the link of my project source code
http://www.megafileupload.com/en/file/486016/TableVIewTestSample-zip.html
or
http://www.2shared.com/file/PgExc8W_/TableVIewTestSample.html
When run the code click on "Push" button on the screen and then wait 4 second at the 2nd screen and click back button. The cell are not released.
Can anybody run the code and suggest any fix for this.
I haven't looked at your code but cells aren't necessarily released when you reload. Cells are built to be re-used, so just reloading the data doesn't necessarily free the old cells. (There's no reason to free and re-create a cell if you've already created enough cells.)
In general if you create a tableView and scroll around you shouldn't see any cells released. You should see them released only when you nuke the tableView (that's when it's sure it won't need them again) and a few other situations.
(On the other hand, you might just be leaking the cells.)
This issue exist in iOS 7.0.0 to iOS 7.0.2. The cells do not release when we perform the "reloadRowsAtIndexPaths" method. This issue is solved in iOS 7.0.3.

Resources