Ios 如何从UITableView部分获取选定的UISwitch标记?

Ios 如何从UITableView部分获取选定的UISwitch标记?,ios,objective-c,uitableview,Ios,Objective C,Uitableview,如何从多个部分获取UISwitch标记。我有3个部分,用户可以更改开关状态。基于此,我想得到开关标签和节索引 您可以预先设置 switch.accessibilityValue = "\(indexPath.section)" 回来 let section = Int(cell.accessibilityValue ?? "0") 关于表格视图中的页眉,您还需要了解一件事,即覆盖页眉高度。您可以这样做: - (CGFloat)tableView:(UITableView *)tableVie

如何从多个部分获取UISwitch标记。我有3个部分,用户可以更改开关状态。基于此,我想得到开关标签和节索引

您可以预先设置

switch.accessibilityValue = "\(indexPath.section)"
回来

let section = Int(cell.accessibilityValue ?? "0")
关于表格视图中的页眉,您还需要了解一件事,即覆盖页眉高度。您可以这样做:

- (CGFloat)tableView:(UITableView *)tableView 
   heightForHeaderInSection:(NSInteger)section
{
   return 50;
}

这就是答案,它对我有用

UITableViewCell *cell = (UITableViewCell *)mySwitch.superview.superview;
NSIndexPath *indexpath = [_deviceRulesTableView indexPathForCell:cell];
NSLog(@"toggle section %ld rowID %ld", (long)indexpath.section, (long)indexpath.row);

if (indexpath.section == 1) {
}

你的问题模棱两可。请添加更多信息和一些代码。显示您尝试过的代码
UITableViewCell *cell = (UITableViewCell *)mySwitch.superview.superview;
NSIndexPath *indexpath = [_deviceRulesTableView indexPathForCell:cell];
NSLog(@"toggle section %ld rowID %ld", (long)indexpath.section, (long)indexpath.row);

if (indexpath.section == 1) {
}