我試圖從UITableView中刪除單元格,如果單元格的圖像是壞圖像。基本上我的代碼執行線程池呼叫針對每個小區的圖像,使其平滑的數據綁定作爲用戶滾動作爲所以GetCell方法內部的流動:在GetCell方法中刪除動態單元格
public override UITableViewCell GetCell (UITableView tableView, MonoTouch.Foundation.NSIndexPath indexPath)
{
//other stuff
ThreadPool.QueueUserWorkItem(new WaitCallback(RetrieveImage),(object)cell);
}
異步方法內我所說的cell.imageUrl屬性和它綁定到一個NSData對象像這樣:
NSData data = NSData.FromUrl(nsUrl); //nsUrl is cell.imageUrl
從那裏我知道,如果數據== NULL再有就是檢索圖像,所以我想刪除它的一個問題。我目前所做的是將隱藏屬性設置爲true,但這留下了空白區域。我想刪除整個單元格,以便用戶甚至不知道它的存在。 我無法將單元格高度設置爲0,因爲我不知道imageUrl是否壞,直到該indexrowpath啓動getcell調用。我不想僅僅檢查綁定到UITableView的數據中的所有圖像,因爲這可能會是一個很大的性能問題,因爲它可以很容易地處理一百個項目。我目前正在從web服務中獲取物品,這些物品爲我提供了前200個物品。 我怎樣才能去除細胞altogther 如果數據== NULL例如
NSUrl nsUrl = new NSUrl(cell.imageUrl);
NSData data = NSData.FromUrl(nsUrl);
if (data != null) {
InvokeOnMainThread (() => {
cell.imgImage = new UIImage (data);
//cell.imgImage.SizeToFit();
});
} else {
//I tried the below line but it does't work, I have a cell.index property that I set in the getCell method
_data.RemoveAt(cell.Index);//_data is the list of items that are binded to the uitableview
InvokeOnMainThread (() => {
//cell.Hidden = true;
});
}