【发布时间】:2016-03-09 02:28:28
【问题描述】:
我有一个UITableView,其中包含这么多行。在我的屏幕中,UISwitch 可以在UITableView 的几行中添加。请告诉我该怎么做?
我应该使用
UISwitch创建一个自定义单元格并显示或隐藏UISwitch。我是否应该直接从
cellForRowAtIndexPath:中的代码添加 UISwitch。
有什么建议吗?
编辑:
我已经尝试过这段代码,但这不起作用。
SettingsCell *cell;
static NSString *CellIdentifier = @"SettingCell";
if (cell == nil)
{
cell = [tableView
dequeueReusableCellWithIdentifier:CellIdentifier
forIndexPath:indexPath];
[cell setSelectionStyle:UITableViewCellSelectionStyleDefault];
[tableView setSeparatorStyle:UITableViewCellSeparatorStyleSingleLine];
}
if(indexPath.row==2 || indexPath.row==3)
{
cell.switch_value.hidden=false;
}
else
{
cell.switch_value.hidden=true;
}
cell.label_text.text = [VALUES objectAtIndex:indexPath.row];
return cell;
【问题讨论】:
-
和我一样。我用 UISwith 创建了一个自定义单元格,并根据单元格显示或隐藏它
-
我已经用一些代码示例编辑了我的答案。
标签: ios iphone xcode uitableview ipad