예제 #1
0
            public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath)
            {
                var cell = tableView.DequeueReusableCell(CellIdentifier) as VoteNowCellView;

                // Data
                var item = Items [indexPath.Row];

                cell.Tag = item.Id;
                cell.UpdateUIWith(item);

                if (SingleSelection && 0 == indexPath.Row)
                {
                    cell.IsChecked = true;
                    cell.btnCheck.SetImage(CheckedImage, UIControlState.Normal);
                    SelectedIndex.Add(item.Id, true);
                }
                else
                {
                    cell.IsChecked = false;
                    cell.btnCheck.SetImage(UnCheckedImage, UIControlState.Normal);
                }


                cell.btnCheck.TouchUpInside += (sender, e) => {
                    var index = (int)cell.Tag;
                    if (cell.IsChecked)
                    {
                        if (SingleSelection)
                        {
                        }
                        else
                        {
                            if (SelectedIndex.Keys.Contains(index))
                            {
                                SelectedIndex.Remove(index);
                            }

                            cell.IsChecked = false;
                            cell.btnCheck.SetImage(UnCheckedImage, UIControlState.Normal);
                        }
                    }
                    else
                    {
                        for (int lt = 0; lt < Items.Count; lt++)
                        {
                            var p = NSIndexPath.FromRowSection(lt, 0);

                            var tempcell = tableView.CellAt(p) as VoteNowCellView;

                            tempcell.IsChecked = false;

                            tempcell.btnCheck.SetImage(UnCheckedImage, UIControlState.Normal);
                        }

                        cell.IsChecked = true;
                        cell.btnCheck.SetImage(CheckedImage, UIControlState.Normal);

                        if (SingleSelection)
                        {
                            SelectedIndex.Clear();
                            SelectedIndex.Add(index, true);
                        }
                        else
                        {
                            if (!SelectedIndex.Keys.Contains(index))
                            {
                                SelectedIndex.Add(index, true);
                            }
                        }
                    }

                    var args = new AnswerSelectedEventArgs {
                        SelectedAnswer = item
                    };
                    OnAnswerSelected(args);
                };

                return(cell);
            }