combine two functions into a UITableViewCell: selection and information - iphone

I'm using a UITableView to present options to the user. The user can select one option by clicking on one of the cells. The concept is similar to the Radio input in html forms.
I'm looking for some ideas on how to combine two functions into a UITableViewCell.
I've taken care of the selection function. I would like to also let the user get information on a particular UITableViewCell.
The information is text that will not fit into a subtitle on the UITableViewCell.

Create mirror arrays, one with info for the selection, and one with the other information; then on selection, insert the other info into the first array in the appropriate position and display
Or
Create a footer under the tableView and display the info whenever a cell is selected.

Related

Swift: how to enable or disable multiple buttons embedded in custom classes at once?

Q: How do you enable multiple buttons when they are embedded inside custom cell classes?
Working example: Users are presented with a list of fruit to categorise. They select a banana and tap a colour category - in this case, yellow. Banana is added to the 'yellow' fruit list.
In this scenario, 'colour categories' are UICollectionView headers. The fruit are UICollectionView items. I'm trying to enable an 'Add Fruit' button (which is defined in a custom header cell class) when a user selects a fruit, for good user feedback.
However, I can't figure out how to bulk enable the buttons (within the headers) on selection. I first thought to create a variable on my custom cell which uses didSet() to enable the button, but I need to reload each UICollectionView header to set the variable, which I don't know how to do. I then created a variable on the collectionView itself which used reloadData(), but this removes the user's selected cells.
How do I get multiple buttons to enable at once, without resetting the entire collectionView?
You can use IBOutletCollection. It provides connection to multiple outlets at once but similar kind of outlets, for eg. you need to connect multiple buttons or multiple labels.
Refer to this to understand IBOutletCollection
https://medium.com/#abhimuralidharan/what-is-an-iboutletcollection-in-ios-78cfbc4080a1

How do I make an editable detail view on the iPhone with a grouped UITableView?

I want to make a grouped TableView similar to the Apple iPhone contacts application.
I need a lot of standard fields which can be edited, but I would only like them editable once the edit button in the navbar is clicked.
This has been bothering me forever that I could not find a good tutorial.
Thanks in advance.
This is not easy. I just built the same thing because there is nothing available from Apple. I ended up creating a single table cell with a UILabel and a UIView on it. The UILabel is for when the cell is in read mode, and the UIView is for editing. The UIView contains a number of UITextFields. These are the individual fields. I also had to implement drawing code to draw the lines between the fields. Then I had to come up with the code to pass in an address object, load it into the fields, format the text for the label, switch in and out of editing mode (with animation), and finally handling saving of changes and canceling. As yet it doesn't handle tapping the address type to select that from a popup list, but I have most of the code in place for the rest.
This could have been done using individual table view cells for each field. But then you can't select the whole thing the way it does in contacts and adding and deleting addresses becomes trickier.

Three20 TTSectionedDataSource row height

I'm using Three20 to create a table with several textfields for user registration. I've found two possible methods using Three20. The first uses the TTSectionedDataSource's tableDidLoadModel method to manually add UI components and the second adds custom items that contains pre formatted UI components. The second option seems way more complex and I'm having a difficult time accessing the individual fields. So if one field is a textfield for the username, I need to access the field to submit the username and it doesn't seem like there's an easy answer. The first option gives me a lot of flexibility, but I can't figure out how to set the individual row heights. One row may have a label above a text field, another may have an image, etc. Is there a method that can be used in TTSectionedDataSource that will allow me to set the height for each row? Thus far, I'm using method one and creating UIViews to hold a label field and a text field. I've tried changing the frame of the uiview before it is added to the items array, but it has no affect.
Any ideas?
I believe I may have figured it out. Not sure if this is the correct solution, but it seems to be working.
First in my custom item class I pass the datasource as a delegate. Now that the delegate is part of the item, I can pass it to my textfield as the delegate. As long as I include UITextFieldDelegate in my data source class, it will respond as the delegate to my textfield. So that's getting the content from the textfield.
If I want to change the content in a textfield from the datasource, I can leverage the method:
- (void)tableView:(UITableView*)tableView cell:(UITableViewCell*)cell willAppearAtIndexPath:(NSIndexPath*)indexPath
I can check the row using indexPath.row then type the cell as the corresponding custom cell class. From there I can access any public methods in my cell class. So I created one that returns a reference to the textfield. So I can say:
[[(MyCustomTextFieldCell *)cell theTextField] setText:#"hello world"];
Next step is to assign it to a local ivar and then I'm assuming I should be able to access it at any time.
The main reason I want to be able to modify the content of the textfield is that in certain instances by clicking on the textfield, a picker will come up and the results of the picker are formatted and inserted back into the textfield.
Please let me know if my approach is too convoluted. Perhaps I'll create a sample and post it for everyone to rip apart and tell me I'm a moron and there's a better way.
thanks,
howie

iPhone -- customizing a grouped table view in Interface Builder

I am writing an iPhone app. According to the design, it is supposed to contain a lot of grouped table views. In these views, the rows are frequently not similar to each other. For example, on one screen, one row is the name of a task, another is its owner, another is its description, yet another is its history (which is supposed to be an expanding box), and so on. These rows are edited in different ways. For example, the name can be entered free-form, but the owner has to be chosen from a list, which would be brought up in a further table view.
I think doing all of this programatically would drive me batty. What I want is a way to design these screens in IB. But I can't figure out how to get IB to do treat the cells individually. Is that possible?
Thanks.
In Interface Builder you create custom UITableViewCells for each row and then return the appropriate custom cell in – tableView:willDisplayCell:forRowAtIndexPath:. You also need to return the height of each custom cell in – tableView:heightForRowAtIndexPath:.
Within Interface Builder, you create a custom cell just like you would any view. You size the cell and then fill it with subviews. It's best if you create a UITableViewCells subclass for each custom cell that has IBOutlets that connect to each subview. That way you can easily access labels, imageviews, controls etc.

Determine section index from UITableView section header or footer?

I have a multi-section table view, and each section has a button in its footer that should add a new item to that section. The number of sections is not pre-determined or limited, so I can't make a separate selector for each section like "addItemToSection1", etc.
I also can't just store the section index in the button's "tag" property since the table also supports adding or removing arbitrary sections, which changes the section indexes for all following sections.
The only thing I can think of is to maintain my own, separate map from buttons to sections or something similar, which is a lot more fiddly gruntwork than I'd like. Is there any way to determine directly what section a given header or footer is in?
Re: gerry3's answer above (Added as an "answer" because SO won't allow me to comment on the above answer for some reason.)
Thanks for the info. It seems there is no way to avoid having to maintain a separate data structure to map sections to and/or from the underlying model, since I have to have the section index so I can call things like insertRowsAtIndexPaths:withRowAnimation:, and since the section indexes can change due to adding or removing sections. How annoying!
I have seen a few methods for associating a button to its tableview cell or, more importantly, the row or data associated with that cell. You should be able to do something similar for tableview sections.
Use the button's tag. In the button's action selector, use the button's tag to get the data. It sounds like you have already ruled this out.
Use a custom view for the section which has a property for its associated data and the button as a subview. In the button's action selector, get the specific instance of your custom view as your button's parent view. Then, get the data from the custom view's property.
Put the button in an array of buttons and the data in an array of data at the same index as the corresponding button. In the button's action selector, find the index of the button in the button array and grab the data from the data array using that index.