Sebastian Boldt Sebastian Boldt - 4 months ago 13x
iOS Question

Best approach to add Static-TableView-Cells to a UIViewcontroller?

I want to add a tableview-look-a-like-login to my app, but it seems to be not that easy to implement. I tried to accomplish my goal using more then one approach, but i am not sure about which solution is the best.

For example, Dropbox and Facebook have a login page like this.

Here are my 3 approaches :

  1. I added 2 UITextfields to my View (no border) and placed a . png behind, which looks like a tableviewcell. ( Not the best approach cause i want to use real tableviews )

  2. I added a Container View to my ViewController placed a tableview with static Table Views inside. The Problem here is, that i dont know how to access the information inside my viewcontroller?

  3. I added a tableview to my ViewController and used dynamic cells with it. Connected the outlets for delegate and datasource to my viewcontroller and initialized them with the delegate and datasource methods. The Problem here is, that i can not use static table views inside a uiviewcontroller.

Is there any better way of solving this problem ?
I would really like to know how to do this in a more elegant way.


A ContainerViewController basically solved this issue for me some month ago.
After embedding one into the main controller you can access it through the
function and define a protocol-based interface for that specific controller to interact with the embedded controller.


I have an idea how to solve this. I think it's a clean way to do so. You do not need storyboard for this controller.

Make your controller subclass UITableViewController like so:

@interface YourViewController : UITableViewController

Then in your viewDidLoad you create the instances of the cells:

- (void) viewDidLoad {
    usernameCell = [YourTextFieldCell new];
    passwordCell = [YourTextFieldCell new];

The YourTextFieldCell is of course your own subclass of a UITableViewCell, which could be something like this:

@implementation YourTextFieldCell {
    UITextField textField;
- (id) init {
    self = [super init];
    if (self) {
        // Adjust the text's frame field to your liking
        textField = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, 200, 20)];
        [self addSubview:textField];
// A getter method to access the textfield from the outside
- (UITextField *) textField {
    return textField;


Back in YourViewController:

- (NSInteger) tableView:(UITableView *) tv numberOfRowsInSection:(NSInteger) section {
    return 2;
- (UITableViewCell *) tableView:(UITableView *) tv cellForRowAtIndexPath:(NSIndexPath *) indexPath {
    if (indexPath.row == 0) {
        return usernameCell;
    } else if (indexPath.row == 1) {
        return passwordCell;
    return nil;

Do you get where I am going with this? This is how I think you should do it! Good luck!