如何优化tableview单元格颜色的其他条件
public override UITableViewCell GetCell (UITableView tableView, MonoTouch.Foundation.NSIndexPath indexPath){
var cell = tableView.DequeueReusableCell (TableCell.Key) as TableCell;
if (cell == null)
cell = new TableCell ();
cell.Accessory = UITableViewCellAccessory.DisclosureIndicator;
if (indexPath.Row % 2 == 0) {
cell.BackgroundColor = UIColor.White;
} else {
cell.BackgroundColor = UIColor.LightGray;
}}
最佳答案
这里几乎没有什么可以优化的了。我唯一要更改的是最后一个if
-我将其替换为条件表达式:
public override UITableViewCell GetCell (UITableView tableView, MonoTouch.Foundation.NSIndexPath indexPath){
var cell = tableView.DequeueReusableCell (TableCell.Key) as TableCell;
if (cell == null) {
cell = new TableCell ();
}
cell.Accessory = UITableViewCellAccessory.DisclosureIndicator;
cell.BackgroundColor = (indexPath.Row % 2 == 0) ? UIColor.White : UIColor.LightGray;
}
不过,这是个人喜好问题:带有两个分配的
if
语句也很容易阅读。
关于c# - 优化条件,否则xamarin iOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25461795/