【问题标题】:How do i get the effect of a UISwitch as the accessory for a UITableViewCell?如何获得 UISwitch 作为 UITableViewCell 附件的效果?
【发布时间】:2010-02-28 10:41:40
【问题描述】:

我有一个可用的 UITableView,其中填充了我的应用程序的一些选项,我想像设置应用程序一样向它们添加 UISwitches,我该怎么做?

谢谢:)

【问题讨论】:

    标签: objective-c uitableview uiswitch


    【解决方案1】:

    您可以创建自己的自定义附件视图。在处理tableView:cellForRowAtIndexPath: 时,只需在行单元格中创建一个开关,如下所示:

    UISwitch* turboSwitch = [[UISwitch alloc] initWithFrame:CGRectMake(0.0, 0.0, 84.0, 27.0)];
    [turboSwitch setOn:[engine.turbo boolValue]];
    cell.accessoryView = turboSwitch;
    cell.textLabel.text = @"Turbo";
    

    不要忘记将目标操作连接到您的控制器。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多