views:

322

answers:

2

I want to use a UITableView for my settings screen. So that my settings view will look like apple does it, with a group table view, and then the UI elements to let you change settings.

So, it does not seem like the cells are loaded from an array, but seems like each one is customized.

Ideas on how to do this?

+1  A: 

For starters, set the tableViewStyle property to UITableViewStyleGrouped. Then change the data source to provide 2D arrays with the groups you want, instead of a simple array. It's pretty simple, actually.

You will need to customize the row with UIControl types that you want - I assume you're already doing that though.

EDIT:

To add the control to the row, create it when you create the cell.

...
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button setFrame:CGRectMake(0.0f, 5.0f, 30.0f, 30.0f)];

[button setTitle:@"Click Me!" forState:UIControlStateNormal];
[button addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
[cell addSubview:button];
...
psychotik
Yes, I have already set it to grouping. I guess I am confused about how I would use an array for this, since each cell would have a different layout.
Nic Hubbard
edited with what I think you're looking for
psychotik
A: 

You can do it without an array. Just use the following methods

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

and then can use a switch-method to parse thru all rows and sections. Those two lines on the header of the methods on top and you can short it up a bit.

NSUInteger row = [indexPath row];
NSUInteger section = [indexPath section];

Don't forget, that manual tableviews are prone to errors.

cheers Simon

Simon