views:

1832

answers:

2

I have a complex settings style table where individual cells represent different aspects of a data model class. Users can click into a cell and edit individual attributes, such as say if I have a user class, a name, date of birth, etc. My question is, do I need to have an instance of UITextField for each unique cell? Can I just create one subclass of UITableViewCell, set up a delegate, and determine where it is from there?

What's the best approach?

+1  A: 

I would recommend creating a subclass of a UITableViewCell. You could do this either purely programaticaly, or if you have an aversion to CGRect's (or want to be able to drag and drop your layout around) with a combination of a XIB and a custom class file.

The Subclass would then contain the UITextFiled's you need, and can also have a delegate or datasource that you can use to point it to your data model object.

Brad Smith
A: 

It's better to have the UITableViewController you are using act as the text view delegate for each cell - make sure you are re-using cells and when you create them or reuse them attach your class as the delegate for the UITextViews you have via a custom UITableViewCell class with accessors to get to the UITextViews.

If you set cell classes as text delegates you may run into issues if the user scrolls a table view cell off screen with the keyboard up.

Kendall Helmstetter Gelner