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.
Related
i have reloaded the view that contains table view. But when i keep on rotating the table view frequently the app crashes saying:
Terminating app due to uncaught exception 'NSGenericException', reason: '8 Collection <__NSArrayM: 0x7fdd5d460250> was mutated while being enumerated.'
I have implemented a simple table view with its delegates.
Can anyone suggest what actually this means.
looks like on rotate you are reloading the dataSource and while doing so your array is not fully populated and you are trying to change the array while its still have a reference somewhere else.
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.
I wonder how implementing two different ViewControllers and their own classes on the same page. Feed page both of them, and then I wanna pass them using left/right swipe gesture. But I don't know exactly how combining these pages together.
If someone explain as detailed It would be great.
Update
I have added Bridging header and your lines of codes, after editing new ViewControllers and identifier. But When I run and open this view, application stopped with below error.
All my views WishVC, TestVC1, TestVC2 are blank, there are no object.
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSArrayM insertObject:atIndex:]: object cannot be nil'
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.