编辑模式下 UITableView 单元格中的 UISwitch [英] UISwitch in a UITableView cell in editing mode

查看:29
本文介绍了编辑模式下 UITableView 单元格中的 UISwitch的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我按照 UITableView 单元格中的 UISwitch 将 UISwitch 放在 tableview 中.代码如下:

I followed UISwitch in a UITableView cell to put a UISwitch inside a tableview. Here is the code:

UISwitch *mySwitch = [[UISwitch alloc] init];
cell.accessoryView = mySwitch;

但问题是当我将表格置于编辑模式时:

But the problem is that when I put the table into editing mode:

self.tableView.editing = YES;

UISwitch 消失了.

The UISwitch dissapears.

你知道我该如何解决这个问题吗?

Do you know how can I go around this issue?

推荐答案

UISwitch 添加到单元格的 contentView.

Add UISwitch to contentView of cell.

UITableViewCell 对象的contentView 是单元格显示内容的默认superview.如果您想通过简单地添加其他视图来自定义单元格,您应该将它们添加到 contentView 中,以便在单元格进入和退出编辑模式时将它们适当地定位.

The contentView of a UITableViewCell object is the default superview for content displayed by the cell. If you want to customize cells by simply adding additional views, you should add them to the contentView so they will be positioned appropriately as the cell transitions into and out of editing mode.

[[cell contentView] addSubview:switch];

这篇关于编辑模式下 UITableView 单元格中的 UISwitch的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆