2015-11-04 89 views
1

由於性能的原因,我在應用程序中實施了100條消息的聊天,突然間我發現,行編輯並不像我所期望的那麼容易。 所以,我想這一點:Xamarin iOS UITableView,如何刪除第一行?

public void RemoveTopRow() 
{ 
    messages.RemoveAt (0); 
    tableView.ReloadData(); 
} 

但它與本地例外,我沒有在這裏停止崩潰,這嘗試之一:

tableView.DeleteRows (new NSIndexPath[]{ NSIndexPath.FromItemSection(0,0) }, UITableViewRowAnimation.Fade); 

但是,相同的結果:原生崩潰 enter image description here

也許有人知道如何做到這一點?我的下一個休假期間,小小的工作代碼示例會很有幫助,我會做一些重構並在github上發佈這個聊天客戶端,這樣其他人就可以在他們的項目中實現它,而無需UI的痛苦,因爲我已經花了太多時間和神經上的佈局修復

回答

1

沒有看到,你打電話給你RemoveTopRow方法,我只能猜測,但是從錯誤中,我假設在添加一個新的聊天行的中間並刪除從FIFO堆棧中的第一個前的tableview /數據源完成同步:

 public void RemoveTopRow() 
     { 
      dataSource.Objects.RemoveAt (0); 
      TableView.ReloadData(); 
     } 

     void AddNewItem (object sender, EventArgs args) 
     { 
      dataSource.Objects.Add (DateTime.Now); 

      // This will cause the error that you are seeing when 
      // it reaches the TableView.InsertRows... 
      //if (dataSource.Objects.Count > 10) { 
      // RemoveTopRow(); 
      //} 

      using (var indexPath = NSIndexPath.FromRowSection (0, 0)) 
       TableView.InsertRows (new [] { indexPath }, UITableViewRowAnimation.Automatic); 

      //This will work 
      if (dataSource.Objects.Count > 10) { 
       RemoveTopRow(); 
      } 
     } 
+0

woah mate,我猜你對!將盡快檢查,謝謝回覆! –

0

你需要使用插入前調用BeginUpdates()/刪除,一個nd之後調用EndUpdates()。像圖片一樣。 enter image description here

希望它能幫助你。 任何關於Xamarin.iOS的問題歡迎。