so I have a problem with UITableView. I have self-sizing cells and one can actually change height as the UITextView inside changes. When I set the UITableViewController editing, I get an index out of bounds crash by the super.
The crash occurs on this line:
super.setEditing(editing, animated: animated)
Error I get is:
Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndexedSubscript:]: index 7 beyond bounds for empty array'
This out of bounds crash is not caused by a line of code that I wrote since I checked every instance where I access an array and none of them are being called when the crash occurs. The exception breakpoint points to the above line too so I am convinced this has something to do with the default UITableViewController implementation of setEditing: animated:.
An interesting point is that this error only occurs when the resizable cell is in the table view. When I create the table view without it, there are no issues. There are also no issues if I keep the cell in but don't touch any of the constraints so that it doesn't change its height. This leads me to believe that somehow a cell that changes height "in real-time" causes this strange crash but since I can't see into UITableViewController implementation to find the line that causes a bug, I don't know how to handle this problem.
Thanks
EDIT
Turns out that a more precise cause for the crash is when a cell tries to change its height as a direct result of a change in editing. So for example, a cell that simply grows or shrinks due to a text view with beginUpdates() and endUpdates() shouldn't cause any problems. But expanding a cell when starting editing is when this issue arises.
Related
Recently, I have been assigned to deal with crash reports and I found that there are a lot of crash report that come from 'NSInternalInconsistencyException' that are originated from 'UICollectionView'. The 2 reasons that were common are
'Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UICollectionView dataSource is not set'
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'request for number of items in section 0 when there are only 0 sections in the collection view'
I was not able to reproduce the crash. I'm sorry that I am not able to post the code or the full crash report, but I will try my best to briefly explain the situation.
I have a UIViewController that is holding a UICollectionView. The UIViewController acts as the dataSource and delegate for the UICollectionView. And the dataSource and delegate are assigned in the storyboard.
First, I thought that somehow the dataSource disappear somewhere, which would have cause the crash. So I tried to force the crash by setting dataSource = nil, but as expected it did not crash. I also found a solution here which says to check if dataSource in layoutAttributesForElementsInRect is equal to nil or deal with it accordingly. I tried to force dataSource = nil in there, but still can't reproduce the problem (
UICollectionView and Supplementary View crash)
Is it possible that somehow the UIViewController that acts as a dataSource for the UICollectionView died somehow so UICollectionView does not have the dataSource? But wouldn't this be the same as UICollectionView.dataSource = nil, which would not crash the app anyway?
Would it help if I separate UIViewController and UICollectionViewDataSource and then assign the dataSource in the viewDidLoad?
I would greatly appreciate it if someone could point me to the right direction in solving this problem.
Thanks
Edited: found a similar problem here iOS 9: UICollectionView dataSource is not set However, there is no solution yet.
I have a Swift Application that has a table view, where inside each cell is another sublist which we keep in a second table view.
Each table view cell is composed of a Header area, another table view with sub items, and a footer area.
For some reason when you click right below the inner table view (highlighted in the image), it triggers an NSInvalidArgumentException with the following error and a long stack trace that isn't very helpful (I can provide it if someone thinks it will help).
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UITableViewCellAccessibilityElement superview]: unrecognized selector sent to instance 0x7cd5f480'
I've set an exception breakpoint, but the debugger points to the AppDelegate on class initialization and provides no detailed info of where the error could be occurring.
I've experimented commenting out the code where I set the inner table view's delegate and datasource, and when I do so the error stops occurring, so I think that indicates that something is wrong with the inner table view.
The source code for the Custom Cells in question is located here
I'm assuming that the problem has something to do with accessibility, but I honestly have no idea what that even is, and have not been able to find related errors from my google searches. Thanks for the help!
First off,
You should not have a table view inside of another table view. This can cause problems, as you have found. I suggest that you adjust your code to insert cells dynamically and have multiple cell types.
As for your accessibility error, I would try toggling the accessibility checkbox on the storyboard under the Identity Inspector.
If you have any other questions, please let me know.
I am using an UITableView for showing some data. Now when an user tap on a cell I appended a new cell just below the taped cell to show some more extra information. Everything is working fine. It's has two sections. Now if I tap on a cell of section 1 it's append a new cell as it should be. Then I do down scroll and the appended cell & it's parent cell is going out of the visible rect. And when I do up scroll it's shows back. No issue. But the problem is if I scroll up very fast it got crashed on the below line.
UITableViewCell *parentCell=[tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:[indexPath row]-1 inSection:[indexPath section]]];
In console it shows
***** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 5 beyond bounds [0 .. 4]'
If I scroll slowly it's works fine only got crashed if I do it fast. And very strange is if I do the same for section 0. It's not got crashed. Guys please help me. I already spent lot of time to figure out this but fail. Thanks in advance.
The -1 in [indexPath row]-1 is almost certainly wrong; the row is zero-based and so are your data structures (well they are if you keep your data in an NSMutableArray or somesuch).
However this doesn't tally with the exception "5 is greater than 4", so I'm assuming you are making "+1" and "-1" adjustments here and there which is breaking your app.
I'm pretty sure you don't have to make these adjustments at all, however I cannot tell for certain without seeing more code.
I am using a subclassed tableView made by someone else and it comes with a method loadObjects that causes the tableView to repopulate its cells, however it doesn't tell the table view to return to the top after the repopulation. I tried to implement this feature with:
- (void)loadObjects{
[super loadObjects];
[self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:YES];
}
However once loadObjects is called (when the table view wants to initially load), i get the following exception:
*** Terminating app due to uncaught exception 'NSRangeException', reason:
'-[UITableView _contentOffsetForScrollingToRowAtIndexPath:atScrollPosition:]:
row (0) beyond bounds (0) for section (0).'
I transferred the line I wrote that scrolls the table view to the top to another custom method that is called whenever I pressed a button, and it worked totally fine, so there is a problem in my overwriting of loadObjects. Does anyone understand the exception that was thrown?
Test reloading the tableview before calling scrollToRowAtIndexPath.
[self.tableView reloadData];
As some of the commenters pointed out, you'll see this error when attempting to scroll to an index path that does not exist (according to the results of numberOfSectionsInTableView and numberOfRowsInSection).
So the fix is to not attempt to scroll to a non-existent index path. You might achieve this fix by changing the order in which this method is called, relative to loading your data (as the commenters suggested), or by some other means (e.g. changing the way you compute which index path to scroll to, or only scrolling conditionally if the index path is sure to exist).
I have a UITableView that I populate with data from an array. It displays available networks, and populates the table view based upon its findings. I try and recall reloadData to the table view in one of my methods, but for some odd reason the app crashed with the error:
*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayI objectAtIndex:]: index 0 beyond bounds for empty array'
To recreate the issue, I first scan for the networks. There are 2 available and they're just chilling. I connect to one, then I go to disconnect. I click disconnect, fire a reloadData to refresh the table view, then that is when the app crashes with the error. If I delete the reloadData call, it doesn't crash and goes along fine. This ties in with another question that I have about refreshing the table view to not display the network unless it's connected to it, I thought reloadData would work but it hates me. I'm at a loss of what to do to fix this bug and refresh properly.