3

I have added a Prototype cell to my UITableView which has a UISwitch and an UILabel. When I run the app the UISwitch and UILabel display fine as expected, but some how I can not interact with the UISwitch. I can not toggle it between On or Off.

I have also tried creating a separate UITableViewCell and implementing the same UI. Still I have the same issue.

I am inflating the Cell as follows :-

public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath)
        {
            RatingTableCell cell = tableView.DequeueReusableCell("RatingTableCell") as RatingTableCell;

            if (choiceList != null && choiceList.Count > 0)
            {
                cell.UpdateCellchoiceList.ElementAt(indexPath.Row));
            }
            else
            {
                //Do something else
            }



            return cell;
        }



 public override void RowSelected(UITableView tableView, NSIndexPath indexPath)
        {
            var cell = tableView.CellAt(indexPath);


        }

EDIT

The whole cell is also not getting clicked. If I just add a label without the UISwitch the cell click works fine.

enter image description here

user3034944
  • 1,541
  • 2
  • 17
  • 35

2 Answers2

22

In case someone comes to this post like me, this might be helpful. If your UISwitch is added manually to the UITableViewCell, make sure it's added to the contentView of the cell. The UISwitch will not work if it's added like addSubview(switch), you need to do contentView.addSubview(switch) instead.

codingrhythm
  • 1,456
  • 14
  • 26
0

Make sure that selection and user interaction is enabled: Selection User Interaction

Christoph
  • 702
  • 6
  • 16