表项[indexPath.Row]背后的数据类型.这是怎么建立起来的



我是C#的新手,现在我看到了这段代码

tableItems[indexPath.Row].Heading

哪个数据类型可能在后面?它像数组一样使用,也使用点表示法。tableItems是一个单独的对象/类吗?或者它是由DictionaryList组成的?我只有一个摘录,不能访问完整的源代码…

我想为我的应用程序构建相同的。我该怎么做呢?

编辑:

我对tableItems[1].Heading部分(没有indexPath.Row)感兴趣。我知道我被否决了,但我对解决方案很感兴趣。给我投票并提供解决方案

基本相同
int index = indexPath.Row;
var row = tableItems[index];
... row.Heading;

不知道(也不能)确切的类型。但tableItems很可能是Dictionary<int, SomeClass>(或任何实现indexer属性的类型)。SomeClass提供了一个属性Heading


自己构建:

class IndexPath {
  public int Row { get; set; }
  public IndexPath(int row) { this.Row = row; }
}
class Row {
  public Heading Heading { get; set; }
  public Row(Heading heading) { this.Heading = heading; }
}
class Heading {
}
var tableItems = new Dictionary<int, Row>();
tableItems.Add(0, new Row(new Heading());
tableItems.Add(1, new Row(new Heading());
// ... and so on
var indexPath = new IndexPath(1);
tableItems[indexPath.Row].Heading;

我在这里找到的:

TableItem.cs

using System;
using MonoTouch.UIKit;
namespace Storyboard {
    public class TableItem {
        public string Heading { get; set; }
        public string SubHeading { get; set; }
        public string ImageName { get; set; }
        public string Url {get;set;}
        public UITableViewCellStyle CellStyle
        {
            get { return cellStyle; }
            set { cellStyle = value; }
        }
        protected UITableViewCellStyle cellStyle = UITableViewCellStyle.Default;
        public UITableViewCellAccessory CellAccessory
        {
            get { return cellAccessory; }
            set { cellAccessory = value; }
        }
        protected UITableViewCellAccessory cellAccessory = UITableViewCellAccessory.None;
        public TableItem () { }
        public TableItem (string heading)
        { Heading = heading; }
    }
}

填充数据

List<TableItem> tableItems = new List<TableItem>();
tableItems.Add (new TableItem("Vegetables") { SubHeading="65 items", ImageName="Vegetables.jpg", Url="http://en.wikipedia.org/wiki/List_of_leaf_vegetables"});
使用

detail.Title = tableItems[indexPath.Row].Heading;

它基本上是一个带有自定义类的List

相关内容

最新更新