繁体   English   中英

在Xamarin iOS中的Uitablesource getcell方法中创建单元格时发生异常

[英]Exception when creating a cell in Uitablesource getcell method in xamarin ios

我正在使用Google Places API提供建议的搜索。 因此,它将为每个字符命中搜索api。 我有一个更新的表源。 这是GetCell方法

public override UITableViewCell GetCell(UITableView tableView,NSIndexPathindexPath)
{
  var cell = base.GetCell(tableView, indexPath) as CityCell;
  cell.SubscriteToCheckEvent(() =>
{
    var ddd = cell as CityCell;
    viewModel.ZipCode = cell.CityNameText.Text;
    viewModel.SearchStoresCommand.Execute(true);
 });
   return cell;

 }

当我尝试快速更新值时出现异常

Index was out of range. Must be non-negative and less than the size of the collection.

有什么办法可以避免这种异常?

任何建议都会有所帮助。

您调用“ GetCell”方法的方式不正确。

这是GetCell的示例:

public override UITableViewCell GetCell (UITableView tableView, Foundation.NSIndexPath indexPath)
        {
            MyTableCell cell = tableView.DequeueReusableCell (CellID) as MyTableCell;
            if (null == cell) {
                //Init custom cell
                cell = new MyTableCell (UITableViewCellStyle.Default, CellID);
                //Bind delete event
                cell.CellClicked += delegate {
                    //Do something for click event
                };
            }
            return cell;
        }

这是我为其他人编写的有关UITableView数据管理的完整示例,您应该看一下:

UITableViewDataManagementSample

您需要共享更多代码,否则我们将无法为您提供帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM