2014-04-01 244 views
0

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? 的iOS如何添加单选按钮

我想在我的ViewController的东西,应该是相同的这幅画(简单密码+单选按钮)的第一项补充。我是否需要使用UITableView并为此定义听者和页脚?有人能给我提供一些如何开始和使用它的例子吗?

+1

我建议你创建一个UITableViewController(或您的自定义类从的UITableViewController inerrited),创建一个UITableViewCell与基本的UILabel和UISwitch,就是这样。使插座连接,瞧:)。这里有一个老例子,但你有这个想法:http://stackoverflow.com/questions/4585840/how-to-create-a-uitableviewcell-with-a-uiswitch-and-get-the-data – Lapinou

回答

1

您需要在单元左侧使用UILabel以及在右侧使用UISwitch的自定义UITableViewCell。

向表格视图和单元格标识符注册自定义单元格类,然后像对其他单元格一样对其进行自定义。

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; 
} 
+0

如果班级我使用的CustomCell是一个UIViewController,我有UITableview,当使用[_tableView注册...]我得到一个错误信息没有可见的接口UITableView声明选择器寄存器。如何解决这个问题? –

0

最简单的解决方案是在界面构建器中使用静态布局来设置UITableViewController。

enter image description here

然后设置你的表,但是你希望它看起来:

enter image description here