tags:

views:

264

answers:

1

Hey there,

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?

A: 

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

Ward