我有一个UITableViewController和每个部分的复选框列表。
的正确方法是什么?...换句话说,我只想在第1部分中使用一个复选标记。我尝试使用NSIndexPath,但这些属性是只读的。
代码
public override void RowSelected(UITableView tableView, NSIndexPath indexPath)
{
if (indexPath.Section ==1)
{
var thisCell = tableView.CellAt(indexPath);
if (thisCell.Accessory == UITableViewCellAccessory.None)
thisCell.Accessory = UITableViewCellAccessory.Checkmark;
else
thisCell.Accessory = UITableViewCellAccessory.None;
}
if (indexPath.Section ==2)
{
var thisCell = tableView.CellAt(indexPath);
if (thisCell.Accessory == UITableViewCellAccessory.None)
{
thisCell.Accessory = UITableViewCellAccessory.Checkmark;
// Somehow deselect all the checkboxes in the other rows
// I can't set NSIndexPath properties on a new object... so I'm stuck
}
else
{
thisCell.Accessory = UITableViewCellAccessory.None;
}
}
}
答案 0 :(得分:0)
创建NSIndexPath的方法位于静态方法...
public override void RowSelected(UITableView tableView, NSIndexPath indexPath)
{
if (indexPath.Section ==1)
{
var thisCell = tableView.CellAt(indexPath);
if (thisCell.Accessory == UITableViewCellAccessory.None)
thisCell.Accessory = UITableViewCellAccessory.Checkmark;
else
thisCell.Accessory = UITableViewCellAccessory.None;
}
if (indexPath.Section ==2)
{
var thisCell = tableView.CellAt(indexPath);
if (thisCell.Accessory == UITableViewCellAccessory.None)
{
thisCell.Accessory = UITableViewCellAccessory.Checkmark;
// Somehow deselect all the checkboxes in the other ro
for (int i = 0; i < 55; i++)
{
if (i == indexPath.Row)
continue;
var tmpRowIndex = NSIndexPath.FromRowSection(i, indexPath.Section);
var otherCell = tableView.CellAt(tmpRowIndex);
if (otherCell == null)
break;
else
otherCell.Accessory = UITableViewCellAccessory.None;
}
}
else
{
thisCell.Accessory = UITableViewCellAccessory.None;
}
}
}