2013-06-21 22 views
0

我在Monotouch.Dialog UITableView中有一系列StyledStringElements。StyledStringElement UITableView中的交替背景

我希望每隔一行設置一個不同的背景顏色(財務報告)。

是否有現有的方法來做到這一點,如果不是,我可以重寫什麼來啓用它?

在一個標準的UITableView我會創造一個新的委託對錶是這樣的:

public class AlternatingTableViewDelegate : UITableViewDelegate 
{ 
    public override void WillDisplay(UITableView tableView, UITableViewCell cell, NSIndexPath indexPath) 
    { 
     if (indexPath.Row%2 == 0) 
     { 
      cell.BackgroundColor = UIColor.White; 
     } 
     else 
     { 
      cell.BackgroundColor = Settings.ColorAlternatingRow; 
     } 
    } 
} 

回答

0

我解決了這個通過添加下面的助手到我BaseDialogViewController類的子類DialogViewController

internal int RowCount = 0; 

    protected StyledStringElement Alternate(StyledStringElement element) 
    { 
     if (++RowCount % 2 == 0) element.BackgroundColor = Settings.ColorAlternatingRow; 
     return element; 
    } 

然後在我創建一個元素之後的代碼中,我將它傳遞給了這個函數。