Matt Facer
Matt Facer

Reputation: 3105

custom cells uitableview - cannot display all the rows

I'm creating a uitableview with custom cells which I created in Interface Builder. There are currently three cells (UITableViewCell).

I have a UITableView which is on the view.

The code I have is fairly standard, but I cannot work out how to actually SHOW the three custom cells. I am using the cellForRowAtIndexPath method.

My aim is to get a grouped uitableview which shows like the following

Item
  - Name

Settings
  - alert
  - time

So the above indented view should be my grouped uitableview. The problem is, I cannot get it to show using code. The uitableview will ALWAYS be this. I am trying to replicate the settings style screen... so I do not have any arrays to display the uitableview cells.

How do I actually display my three cells? I have the following code

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

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (section == 0) 
        return 1;
    else 
        return 2;

}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {

    if(section == 0) 
        return @"Item";
    else
        return @"Settings";
}

So all I need to know is how to actually display my custom cells inside the tableview! Thanks for any information. I've searched for AGES in google .. all the tutorials use arrays to display data!

Upvotes: 0

Views: 841

Answers (1)

Paul Lynch
Paul Lynch

Reputation: 19789

You'll kick yourself.

In cellForRow, use some cascading if statements, like:

if (indexPath.section == 0) {
    cell.textLabel.text = @"Name";
} else {
    if (indexPath.row == 0) {
        cell.textLabel.text = @"alert";
    } else {
        cell.textLabel.text = @"time";
    }
}

Upvotes: 0

Related Questions