views:

14

answers:

2

Hi, I've created a custom UITableViewCell with a label and a text field. I want to create two cells in a group to represent a nice username/password input mechanism.

I've run into some troubles figuring it out (things like the delegate/dataSource). Is there a more direct approach to just add those two cells and get the data inserted into the text fields from code?

P.s. I want the TableView to be only at a part of my screen, the other part will be an "Enter" button... Plus, if it can do it via the interface builder that would be great.

A: 

Interface builder doesn't know about your table view data. If you are confused about setting up a data source, then read the documentation, try the sample code, explore until things make sense. Ask when you get frustrated.

jer
A: 

Although I agree with jer, some pointers about how to still use IB to make table view cells.

Add the cells to your NIB (at root level) and make them look good. Add two IBOutlet UITableViewCell *cell0, *cell1; to your header. Hook up the cells in the NIB to these outlets.

In the class which is your dataSource, do something like:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 2;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    switch ([indexPath row])
    {
        case 0: return cell0;
        case 1: return cell1;
    }
    NSLog("Something bad happened");
    return nil;
}
mvds