Best way to make offscreen table cell subviews available for makeFirstResponder - ios

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.

Related

Grouping messages similar to iPhone Message app

In our iOS application, we are using core data and tied it with a table view using NSFetchedResultsController. The app is about "Chat" feature.
UI is same as that of iPhone "Messages" app. When we tap on a message, it displays the history and all the history grouped with time. The logic behind it is, if previous message and current message are received with a gap of 1 hr, then date & time stamp will be displayed over recent message.
My question is, how can I group the messages and fetch them so that I can show the date & time stamp as well as sender and receiver messages.
There are four types of message cells type - regular, group-start, group-middle, group-end. A group-start message is more than a hour after the last one but less than an hour to the next one. group-middle is less than an hour from the one before and after. group-end is close to the one before it, but more than hour to the one after it. regular is more than a hour before and after it.
There are two parts of this project. One is to display each type of cell correctly. The other is figure-out which type each message is. I assume you can figure out the UI stuff yourself (different padding, for each one, regular and group-start show the time, not rounding some corners, etc).
For each message to figure out its type, is not that hard - just look at the message before it and after it. It can be done in a single run through of the results - O(n). It could also be done lazily with a cache (ie each time a cell load check the message before and after it - save the answer in the cache for next time). If the cell sizes are different for different types then it make cause some weird jumping with estimatedRowHeight. You could also store the results of the type into core-data after you calculate it.
Be careful when a message is inserted to invalidate and recalculate the message cell type for the one above and below it. Also when calculating the message cell type account for situations where there isn't a next or previous cell.
I think you were hoping for some core-data magic - like some cleaver trick with sectionIndexKey. But it is really much more straight forward of just running through the array and calculating it.
Update:
Just to make it clear: don't use sections. Keep all the cells in one section. Just add the time to the top of the cell for the cell type group-start. It is a lot easier than dealing with sections especially when there are inserts that can cause and earlier cell to change from normal to group-start.

Populating tableView inside a collectionViewCell

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!

Creating iTunes store style home view in ios

I want to build a HomePage like iTunes Homepage.
I mean a general UICollectionView with different sections including differentcells. The UICollectionView scrolls vertically but each section scrolls horizontally.
See below image.
I thought of putting a UICollectionView in the UITableCell, but get various different runtime errors.
UITableView collectionView:numberOfItemsInSection:]: unrecognized selector sent to instance 0x7fb009064800
My question is can you help me solve the problem or do you have better way to build this style?
Any help would be appreciated.

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.

Empty Array Error

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.

Resources