【发布时间】:2017-03-09 15:28:28
【问题描述】:
在下图中,下面的 UISwitches 位于集合视图中。但是,我目前面临的问题在哪里。如果我在顶部选择一个开关,例如在屋顶结构中,当我向下滚动另一个不在视图中的开关时,我会选择 NON-SABS APPROVED PRODUCT 开关。
我已按照以下步骤确定如何触发手动点击事件。选择开关时,我使用控制台查看输出。 结果表明,在某些情况下,switch required switch 仅作为第三个事件触发,而触发的另外两个事件是不在用户视图中的开关。
为了尝试解决这个问题,我尝试通过为开关分配一个否定点击事件来解决这个问题。 到目前为止,这还没有奏效,请参见下面的代码
Switch事件的代码
public void btnQuestionAnswer_Click(object sender, EventArgs e)
{
UITableViewRowSwitch btnQuestionAnswer = (UITableViewRowSwitch)sender;
if ((btnQuestionAnswer.section.HasValue) && (btnQuestionAnswer.row.HasValue))
{
db_QuestionAnswer questionAnswer = questionDataModel[btnQuestionAnswer.section.Value].QuestionAnswers[btnQuestionAnswer.row.Value];
//Console.Write(questionAnswer.Answer);
Console.WriteLine(questionAnswer.Answer);
if ((btnQuestionAnswer.On))
{
if (questionDataModel[btnQuestionAnswer.section.Value].ComplianceIndicator)
{
foreach (db_QuestionAnswer QA in questionDataModel[btnQuestionAnswer.section.Value].QuestionAnswers)
{
QA.isTicked = false;
}
}
questionAnswer.isTicked = true;
// ((UICollectionView)btnQuestionAnswer.relatedView).ReloadData ();
}
else
{
questionAnswer.isTicked = false;
}
}
else
{
btnQuestionAnswer.On = !btnQuestionAnswer.On;
}
var element = count.ToString();
}
public override UICollectionViewCell GetCell (UICollectionView collectionView, NSIndexPath indexPath) { UIView 单元格;
if (questionDataModel[indexPath.Section].ComplianceIndicator)
{
cell = collectionView.DequeueReusableCell (QuestionUICollectionViewDelegateDataSource.complianceQuestionCellId, indexPath);
}
else
{
cell = collectionView.DequeueReusableCell (QuestionUICollectionViewDelegateDataSource.questionCellId, indexPath);
}
int row = indexPath.Row;
UILabel lblQuestionAnswer = (UILabel)cell.ViewWithTag (1);
UITableViewRowSwitch btnQuestionAnswer = (UITableViewRowSwitch)cell.ViewWithTag (2);
btnQuestionAnswer.ValueChanged -= btnQuestionAnswer_Click;
btnQuestionAnswer.ValueChanged -= btnQuestionAnswer_Click;
btnQuestionAnswer.ValueChanged += btnQuestionAnswer_Click;
if (row < questionDataModel [indexPath.Section].QuestionAnswers.Count)
{
lblQuestionAnswer.Text = questionDataModel[indexPath.Section].QuestionAnswers[indexPath.Row].Answer;
btnQuestionAnswer.section = indexPath.Section;
btnQuestionAnswer.row = indexPath.Row;
btnQuestionAnswer.On = questionDataModel [indexPath.Section].QuestionAnswers [indexPath.Row].isTicked;
//----------------TODO----------------//
// ----
btnQuestionAnswer.ValueChanged += btnQuestionAnswer_Click;
btnQuestionAnswer.ValueChanged -= btnQuestionAnswer_Click;
//if (!btnQuestionAnswer.hasEvent)
{
btnQuestionAnswer.ValueChanged -= btnQuestionAnswer_Click;
//btnQuestionAnswer.ValueChanged -= btnQuestionAnswer_Click;
btnQuestionAnswer.ValueChanged += btnQuestionAnswer_Click;
//btnQuestionAnswer.hasEvent = true;
}
btnQuestionAnswer.relatedView = collectionView;
if (questionDataModel [indexPath.Section].isLocked)
{
btnQuestionAnswer.Enabled = false;
}
else
{
btnQuestionAnswer.Enabled = true;
}
lblQuestionAnswer.Hidden = false;
btnQuestionAnswer.Hidden = false;
}
else
{
lblQuestionAnswer.Hidden = true;
btnQuestionAnswer.Hidden = true;
}
if (controller.loggedInUser.UserType != "Inspector")
{
btnQuestionAnswer.Enabled = false;
}
return (UICollectionViewCell)cell;
}
【问题讨论】:
标签: ios xamarin.ios uicollectionview uicollectionviewcell