I would like to add in my ViewController something that should look identical with the first item of this picture (Simple passcode + radio button). Do I need to use a UITableView and define the hearder and the footer for this? Can someone provide me some examples of how to start and work with this?
Asked
Active
Viewed 786 times
0
-
1I suggest to you to create a UITableViewController (or your custom class inerrited from UITableViewController), create a UITableViewCell with a basic UILabel and UISwitch, and that's it. Make the outlet connections, and voila :). Here an old example, but you have the idea: http://stackoverflow.com/questions/4585840/how-to-create-a-uitableviewcell-with-a-uiswitch-and-get-the-data – Lapinou Apr 01 '14 at 14:55
2 Answers
1
You need a custom UITableViewCell with a UILabel on the left side of the cell, and a UISwitch on the right side.
Register the custom cell class with the table view and a cell identifier and then customise it as you would any other cell.
static NSString *const CellIdentifier = @"customCell";
/**
* Called after the controller’s view is loaded into memory.
*/
- (void)viewDidLoad
{
[super viewDidLoad];
[self.tableView registerClass:[CustomCell class] forCellIdentifier:CellIdentifier];
}
/**
* Asks the data source for a cell to insert in a particular location of the table view.
*
* @param tableView A table-view object requesting the cell.
* @param indexPath An index path locating a row in tableView.
*
* @return An object inheriting from UITableViewCell that the table view can use for the specified row.
*/
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
cell.textLabel.text = @"Simple Passcode";
return cell;
}

Infinity James
- 4,667
- 5
- 23
- 36
-
If the class where I am using the CustomCell is a UIViewController, where I have UITableview, when using [_tableView register...] I get an error message no visible interface UITableView declares the selector register. How to solve this? – just ME Apr 01 '14 at 18:08
0
Simplest solution is to set up a UITableViewController using static layout in interface builder.
Then set up your table however you want it to look:

David Berry
- 40,941
- 12
- 84
- 95