下圖中的UISwitches位於集合視圖中。不過,我目前面臨的問題在哪裏。如果我在頂部選擇了一個開關,例如在屋頂結構中,當我向下滾動另一個不在視圖中的開關時,請選擇NON-SABS APPROVED PRODUCT開關。UISwitch的UICollectionview單擊事件
我已按照以下步驟來確定如何點擊人類點擊事件。我使用控制檯查看選擇開關時的輸出。 結果顯示,在某些情況下,交換機所需的交換機僅作爲第三個事件觸發,另外兩個觸發的事件是不在用戶視圖中的交換機。
要嘗試解決此問題,我嘗試通過將負面點擊事件分配給交換機來解決問題。 這在目前沒有工作,見下文
代碼代碼爲開關事件
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();
}
公衆覆蓋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;
}
我如何添加更多的控制PrepareForReuse我得到以下錯誤沒有找到合適的錯誤發現修改 – George
您是否正在爲您的單元格使用自定義類?或者正在使用靜態單元? E.g.公共部分類MyDerivedCell:UICollectionViewCell – Digitalsa1nt
class MilestoneViewDelegateDataSource:UITableViewSource {}和class QuestionUICollectionViewDelegateDataSource:UICollectionViewSource {} – George