Three20 TTSectionedDataSource row height - iphone

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

Related

Injecting table cell at end of table

I'm completely new to swift and Xcode and everything regarding iOS development. I have a UITableView that populates UITableViewCells, I've been able to graps the fundamentals of that. But what if I wanted to add an extra cell at the bottom upon every visit?
I guess it's a mix of dynamic and static, but I can't find any answers whether this is case as of present date, since information in threads shows discrepancy.
You need to use dynamic table view. For example you have an array with some elements and your table view is displaying them. If you want to add a cell on the bottom, simply add another element to your array and then call self.tableView.reloadData()

*Editable* Labels of UITableviewCell

I am asking this question as I didn't get any proper/relevant answer
(means I got the answer but not in the form that I want).
Hope anyone of you can provide me the right solution.
OK , My Question is about editable labels.
I have one table view that contains customized cell(s) with 6 different labels in each cell.
What I Want :
1) I want to edit the label when user touches it (Changes will be
saved).
2) When some save button is pressed, I want all the values from the
table view to be saved in an array.
I am attaching screenshot herewith (Hope it may help you to understand my question).
Note :
In the above screenshot what i want is when user touches the "Cotton" word, It can be editable and when user touches the next word (suppose "Pallet") , change in the first word (means in "Cotton") must be saved. There will be one button called "Save"(not in screenshot). When user presses "Save" button , all the values of Tableview should be saved in some array.
It will be very helpful if you can provide me the answer with relevant code.
First of all, in this case, it is best to forget about using labels and use UITextField instead. If you implement UITextFieldDelegate's methods, they will let you know when one starts editing or finishes.
So here is what I would do. Create a subclass of UITableViewCell and make it look exactly how you want it to. Also, it should also have an NSIndexPath property, so you will always know exactly which row gets edited. (if your cells look anything like those in the screen-shots you provided, this step should be rather easy)
Also, it should implement the UITextFieldDelegate protocol and also create one that will let you know when a cell has been edited so you can save it's contents.
In your controller, you should create a temporary array that will be a copy of you data source. When a cell gets edited, you should update the info in your temporary array. On pressing save, you should save this array and make it the data source. Else, just set it to nil and ARC will take care of it.
I can't provide you with code for now, but it shouldn't be hard to code it once you understand the logic.
You have to subclass UItextField so that they can store rowNumber and productName.
Change the UITextField appearance when user taps on it you can catch the touch event on textFieldDidBeginEditing,
And save your Data for a particular row in a dictionary then this dictionary could be saved in an array pointing to the rows of the table .

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.

UITextField and UITableViews... Am I doing this correctly? If not, what is the best way?

I have an array of folders. Each folder is listed as a table view row.
When I display my table, I populate it with a set of textfields on the left hand side of the row (i want the user to be able to edit them) and a set of switches (on/off) on the right hand side of the row.
All is working well, you can touch the textfield and the keyboard appears. You can changed the values of the switch each time also.
The problem I'm having is knowing which text field has been changed so that I can update my array ready to save the values.
I'm using..
[textField addTarget:self action:#selector(textFieldDone:) forControlEvents:UIControlEventEditingDidEndOnExit];
and...
-(void)textFieldDone:(UITextField *)textField
The problem is that the textField object does not contain any unique information about it in the textFieldDone selector. I've tried setting
[textField setTag:rowNumber];
But it doesn't show as tag is not part of the textField object.
Anyone any ideas on the best way of doing this? Surely there must be lots of applications that have have textfields in table rows that you can switch between?
Or maybe I'm missing something here....
Actually 'tag' is part of the UITextField as it is inherited from UIView.
Maybe I can suggest a different approach. Use your table view to display the data with a checkmark in the accessory view if the boolean value you are representing with a switch currently is set to YES. When the user taps that row, push a new view controller that contains a text field and a switch that the user can edit.
Is there an application you've seen that uses the UI method your attempting with the text field and switch in a table cell?
Keep in mind that you are probably reusing table cells, which is what you're supposed to do, however you may not be setting the tag on subsequent uses of that cell. Just guessing here.

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.