cal*_*sto 2 c# uitableview xamarin.ios
如何使用单触控在UITableView中获得交替的行颜色?
我目前使用以下方法填充我的TableView:
public partial class myViewController : UITableViewController
{
public static UINavigationController navigationController;
public static IntPtr handle;
public CompanyViewController (IntPtr handle) : base (handle)
{
}
public override void ViewDidLoad ()
{
base.ViewDidLoad ();
Services service = new Services();
var myList = service.GetList(param1);
List<string> list = new List<string>();
foreach(var c in myList)
{
list.Add (c.Name);
}
navigationController = NavigationController;
handle = Handle;
var source = new CompanyTableSource(list);
myTableView.Source = source;
}
Run Code Online (Sandbox Code Playgroud)
添加此课程:
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 = UIColor.LightGray;
}
}
}
Run Code Online (Sandbox Code Playgroud)
在你的tableview中使用它:
var tvdelegate = new AlternatingTableViewDelegate()
myTableView .Delegate = tvdelegate
Run Code Online (Sandbox Code Playgroud)