1

Update1: Greg Munn と Json が私のコードを見てくれたことに感謝します。現在の段階では、MonotTouch の評価版を使用していることが原因である可能性があります。

Update2: バージョン情報を貼り付けたら、出力も更新されました。

Update3: monotouch 2.0 をインストールした後、アプリをデバイスに展開できましたが、実際のデバイスで発生します。しかし、シミュレーターでは同じ症状が続きます。

UITableViewSource から派生したカスタム クラス (TableSource) を取得しました。シミュレーター (6.1) でテーブル ビューをスクロールしようとするとすぐに、1000 個のセル全体が作成されることがわかりました。私はまだmonoTouchを試していますが、実際のデバイスで実行するとどうなるかわかりません。テーブルビューをスクロールしようとすると、なぜ1000セルが作成されるのか本当にわかりません。何か不足していますか?

出力の一部を次に示します。

Console.Out.WriteLine(string.Format("Created: {0} Reused: {1} - currentRow: {2}", this._totalRowCreated, this._totalRowReused, indexPath.Row.ToString()));
  • 2013-02-20 17:43:16.638 TableViewTest[3039:c07] 新しい行999を作成します
  • 2013-02-20 17:43:16.638 TableViewTest[3039:c07] 作成: 1000 再利用: 0 - currentRow: 999
  • 2013-02-20 17:43:16.638 TableViewTest[3039:c07] 新しい row1000 を作成します
  • 2013-02-20 17:43:16.639 TableViewTest[3039:c07] 作成: 1001 再利用: 0 - currentRow: 1000
  • 2013-02-20 17:43:21.581 TableViewTest[3039:c07] 新しい row11 を作成します
  • 2013-02-20 17:43:21.582 TableViewTest[3039:c07] 作成: 1002 再利用: 0 - currentRow: 11
  • 2013-02-20 17:43:30.650 TableViewTest[3039:c07] row1001 を再利用
  • 2013-02-20 17:43:30.650 TableViewTest[3039:c07] 作成: 1002 再利用: 1 - currentRow: 1001
  • 2013-02-20 17:43:30.651 TableViewTest[3039:c07] 新しい row1002 を作成します
  • 2013-02-20 17:43:30.651 TableViewTest[3039:c07] 作成: 1003 再利用: 1 - currentRow: 1002
  • 2013-02-20 17:43:30.904 TableViewTest[3039:c07] 新しい row12 を作成します
  • 2013-02-20 17:43:30.904 TableViewTest[3039:c07] 作成: 1004 再利用: 1 - currentRow: 12
  • 2013-02-20 17:43:30.905 TableViewTest[3039:c07] 新しい row0 を作成します
  • 2013-02-20 17:43:30.906 TableViewTest[3039:c07] 作成: 1005 再利用: 1 - currentRow: 0

    public override bool FinishedLaunching(UIApplication app, NSDictionary options)
    {
        this.window = new UIWindow(UIScreen.MainScreen.Bounds);
        this.window.MakeKeyAndVisible();
    
        this.viewController = new TableViewTestViewController();
    
    
        this.viewController.View.Frame = new RectangleF(
                0, 
                UIApplication.SharedApplication.StatusBarFrame.Height, 
                UIScreen.MainScreen.ApplicationFrame.Width, 
                UIScreen.MainScreen.ApplicationFrame.Height);
    
        this.window.RootViewController = viewController;
    
        return true;
    }
    

private TableSource _tblSrc;

public override void ViewDidLoad()
{
  base.ViewDidLoad();

  // Perform any additional setup after loading the view, typically from a nib.

  if (this._tblSrc == null)
  {
    this._tblSrc = new TableSource();

    for (int i = 0; i < 1000; i++)
    {
      this._tblSrc.DataItems.Add(string.Format("Row {0}", i));
    }

    this.TableView.Source = this._tblSrc;
  }
}

//---------------------------------

namespace TableViewTest.Models
{
    public class TableSource : UITableViewSource
    {
        private string _cellIndentifier = "MyCellId";
        private List<string> _dataItems;
        private int _totalRowCreated = 0;
        private int _totalRowReused = 0;

        public TableSource()
        {
        }

        public List<string> DataItems
        {
            get{ return this._dataItems ?? (this._dataItems = new List<string>());}
        }

        public override int RowsInSection(UITableView tableview, int section)
        {
            return this.DataItems.Count;
        }

        public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath)
        {
            var cell = tableView.DequeueReusableCell(this._cellIndentifier);

            if (cell == null)
            {  
                this._totalRowCreated ++;
                Console.Out.WriteLine("Create new row" + indexPath.Row.ToString());
                cell = new UITableViewCell(UITableViewCellStyle.Default, this._cellIndentifier);
                cell.Tag = indexPath.Row;
            } else
            {
                this._totalRowReused ++;
                Console.Out.WriteLine("Reuse row" + indexPath.Row.ToString());
            }

            Console.Out.WriteLine(string.Format("Created: {0} Reused: {1}", this._totalRowCreated, this._totalRowReused));


            var value = this.DataItems [indexPath.Row];
            cell.TextLabel.Text = value;

            return cell;
        }
    }
}

MonoDevelop 3.1.1
Installation UUID: 4098f059-8936-47d8-8e66-4e501f33a58b
Runtime:
  Mono 2.10.9 (tarball)
  GTK 2.24.10
  GTK# (2.12.0.0)
  Package version: 210090011
Apple Developer Tools:
   Xcode 4.6 (2066)
   Build 4H127
Xamarin.Mac: Not Installed
Monotouch: 6.0.10 (Evaluation)
Mono for Android: Not Installed

Build information:
  Release ID: 30101000
  Git revision: 5d928ec4f9d5864b4db04a1301b8a8649b43fb9d
  Build date: 2012-12-14 19:11:30+0000
  Xamarin addins: 80f2dcc8fe4ed316b3e77dde496fc33d90305047
Operating System:
  Mac OS X 10.8.2
4

0 に答える 0