Populating tableView inside a collectionViewCell - ios

I am trying to create a UITableView inside a UICollectionViewCell. My goal is to implement a tableview inside my CollectionViewCell and populate my tableView with simple data. I want to create pages of tableViews populated with different categories of data.
I thought it would be a relative easy task, however I am getting a Threat 1: signal SIGABRT error. The debugger is prints
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason:
'-[TableViewMockUp.ViewController tableView:numberOfRowsInSection:]:
unrecognized selector sent to instance 0x100b07cc0'
I am not sure what this error is telling me. When I look inside my ViewController I don't have a tableView numberOfRowsInSection method.
I have the project on Git if you want to take a look: https://github.com/cyrilivargarcia/TableViewMockUp
Below is a snapshot of my ViewController class
This is a snapshot of my CollectionViewClass which is where I created my TableViews.
Any idea on how I can resolve this problem?

-[TableViewMockUp.ViewController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x100b07cc0
I am not sure what this error is telling me. When I look inside my
ViewController I don't have a tableView numberOfRowsInSection method.
You've hit the nail on the head. The error is telling you "you don't have a numberOfRowsInSection method", and your reply is "I don't have one".
So... you just need to add that method to your view controller :)
Edit: After reviewing your code, to clarify for your specific case...
You had your TableView Delegate and DataSource connected to the wrong thing.
In IB, select your table view...
In the Utilities pane, select the Show Connections Inspector
Click the little "x" to delete the current Delegate and DataSource connections
Drag to the CollectionCell in the Document Outline tree
That should do it!

Related

NSInternalInconsistencyException with UICollectionView

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.

Crash in reloadRowsAtIndexPaths: Attempt to delete row containing first responder that refused to resign

I'm stuck on this error. First the code is in swift, not objective C. I am using a UITableView where the the cells can be expanded with additional subviews when selected. When I select a cell, it expands. When I select another cell, the first cell contracts and the new selected cell expands. This is all fine. The code uses this command:
super.viewTable!.reloadRowsAtIndexPaths(cellsToUpdate, withRowAnimation: UITableViewRowAnimation.Fade)
The problem is that one of the subviews in the expanded cell can pop up a UIAlertController when pressed. If I pop up this UIAlertController and cancel it so it goes away, then when I press any other cell in my table, the app crashes with this error:
Assertion failure in -[UITableView _updateWithItems:updateSupport:],
/SourceCache/UIKit_Sim/UIKit-3347.44.2/UITableView.m:2924
2015-10-05 15:59:32.276 MyAppName[46504:1975727] *** Terminating app due
to uncaught exception 'NSInternalInconsistencyException', reason: 'Attempt
to delete row containing first responder that refused to resign'
In other words, everything works fine unless I pop up an alert in the expanded cell. Unfortunately I HAVE TO pop up the alert in the expanded cell to make the program useful. So I need to fix this issue and have no idea how. How can I force whatever is holding on to first responder status in the expanded cell give it up? How can I even see what that first responder is? I have tried to call endEditing(true) and similar sorts of things. I do not have a UITextView as a subview anywhere, so that isn't the problem. Any ideas how to fix this?
I'm open to ideas how toI tried calling reloadData() before the call to reloadRowsAtIndexPaths. Nothing works so far.
UPDATE: Well guess what. There may be a bug in UIAlertController, because when I replace all my UIAlertController code with UIAlertView, everything now works fine, no crashes. Somehow UIAlertController screws up some first responder somewhere so that it now refuses to release first responder status. UIAlertView is a bit more annoying to set up, with UIALertViewDelegate and such, but at least it works without crashing.
But this still begs the question, what could be going wrong in UIAlertController?

Adding xib in CollectionView

Problem such, downloaded and installed MWFeedParser, it worked all right, but that's a problem, I do not need that to show a list of the main xib news, and that he would need to show the menu that I create. But when you try to add a menu, ie create a new a new xib, I choose in the settings (general) in paragraph mainintarface, choose your new xib (MainNav) I get an error
libc++abi.dylib: terminating with uncaught exception of type NSException
Dig deeper into the net, I came across this response, I understand the problem is that I have not added my new xib in UICollectionView? I porobyval remove UIKit.framework, then got out unreal number of errors. Well, actually the question how do I add my new xib in UICollectionView?
You need register your xib cell to your UICollectionView on -(void)viewDidLoad of your view Controller.
[self.collectionView registerNib:[UINib nibWithNibName:#"nibName" bundle:nil]
forCellReuseIdentifier:#"cellIdentifer"];
Click [here] (https://github.com/lequysang/TestCollectionViewWithXIB")

Nested Table Views giving UITableViewCellAccessibilityElement Error

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.

Best way to make offscreen table cell subviews available for makeFirstResponder

I've created a table view based on a feed that contains what is essentially a number of form type elements. Simplified think of it as containing two types of elements textboxes and messages. Textbox type cells should contain UITextFields and Message type cells contain a non editable UITextArea.
I have created a custom cell to handle each of the types and render them into a table. So far so good.
The client has requested a prev/next/done inputAccessoryView like the one that safari uses for html forms. A bit of work later I've got that up and running, I add some functionality that makes prev/next skip over message type cells and only call makeFirstResponder when it finds a textbox type cell. Still things seem to be going smoothly.
Then I added, in testing, a really long message to test my row height setting code. When I try to prev or next over this message cell it fails with a:
2012-02-21 11:34:36.642 MobileMarketing[52410:13a03] -[ContactFormTableViewController selectUpdate:]: unrecognized selector sent to instance 0x89802f0
2012-02-21 11:34:36.643 MobileMarketing[52410:13a03] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[ContactFormTableViewController selectUpdate:]: unrecognized selector sent to instance 0x89802f0'
I assume this is because the target field on the far side of the message and now offscreen has been dequeued. I'm reading up on that. But a long way around for a simple question. Does anyone have a good technique for dealing with this problem?
If I'm understanding your problem correctly, you may be able to solve this using scrollToRowAtIndexPath:atScrollPosition:animated as seen here: https://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UITableView_Class/Reference/Reference.html.
If you scroll to the next cell, you can guarantee it exists before you try to makeFirstResponder.

Resources