c# - UITableView 中的交替行颜色

标签 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;

        }

最佳答案

添加这个类:

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;
        }
    }
}

在你的tableview中使用它:

var tvdelegate = new AlternatingTableViewDelegate()
myTableView .Delegate = tvdelegate

关于c# - UITableView 中的交替行颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13701547/

相关文章:

ios - 在 PFQueryTableViewController 中过滤查询结果

ios - Xamarin/Monotouch 中的 AudioSessionSetProperty

iphone - 使用 LINQ 的设备上的 Monotouch JIT 错误

c# - 使用 Controller 或 View 外部的元数据验证对象

ios - 取消已经启动iOS的UIGesture

c# - Chrome 驱动程序 : How to disable PDF plugin

objective-c - UITableViewCell 选择突出显示颜色

c# - monotouch 中的 Mysql 连接问题

c# - 可以在原始输入中获​​取 Html 节点位置和长度吗?

c# - 从 aspx 页面调用代码隐藏方法