2014-02-13 82 views
0

我使用Xamarin Studio在MonoTouch項目(文件 - >新建 - >文件... - > iOS - > iPhone表格視圖單元格)中創建一個新的自定義表格單元格。它創建了UITableViewCell的MyViewCell子類。該類已經包含一個靜態的Create()方法。MonoTouch中的自定義UITableViewCell

然後我使用這個類表的GetCell方法是這樣的:

public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath) 
{ 
    var cell = tableView.DequeueReusableCell(MyViewCell.Key) as MyViewCell; 

    if (cell == null) 
    { 
     cell = MyViewCell.Create(); 
    } 

    // my own code to update the cell content 
    cell.Update(someData); 

    return cell; 
} 

在更新的方法我用了一些子視圖的轉換。問題是當第一次創建單元格(調用Create方法)時,不會應用轉換。

但是,如果計劃更新下一個運行循環迭代一切正常:

NSTimer.CreateScheduledTimer(TimeSpan.Zero,() => 
{ 
    cell.Update(someData); 
}); 

這裏有什麼問題嗎?我可以在不使用此黑客的情況下解決問題嗎?

回答

0

首次細胞還沒有在表中添加,當你叫更新

細胞轉化子視圖覆蓋PrepareForReuse方法或LayoutSubviews方法對細胞類,這取決於你所需要的。

+0

PrepareForReuse在第一次使用時不會被調用,所以情況並非如此。 LayoutSubviews似乎是解決方案,但它不起作用 - 與創建後立即調用update相同的結果。 – alexey