UITableViewCell中的UISwitch无法正常工作

时间:2017-10-03 06:10:25

标签: ios uitableview xamarin.ios uiswitch user-interaction

我在我的UITableView添加了一个原型单元格,其UISwitchUILabel。当我运行应用程序时,UISwitch和UILabel按预期显示正常,但有些我无法与UISwitch进行交互。我无法在开或关之间切换。

我还尝试创建一个单独的UITableViewCell并实现相同的UI。我仍有同样的问题。

我按照以下方式给Cell充气: -

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);


        }

编辑

整个单元格也没有被点击。如果我只是在没有UISwitch的情况下添加标签,则单击单元格工作正常。

enter image description here

2 个答案:

答案 0 :(得分:6)

如果有人像我一样来到这篇文章,这可能会有所帮助。如果您的 UISwitch 是手动添加到 UITableViewCell,请确保将其添加到单元格的 contentView。如果像 UISwitch 一样添加 addSubview(switch) 将不起作用,您需要改为执行 contentView.addSubview(switch)

答案 1 :(得分:0)

确保启用了选择和用户互动: Selection User Interaction

相关问题