tableView滚动问题xamarin

本文关键字:xamarin 问题 滚动 tableView | 更新日期: 2023-09-27 18:09:01

我们正在iOS 9 (beta)设备上测试我们的应用程序。加载表视图时应用程序崩溃。但同样的代码在iOS 8中执行得很好。

请查找下面的代码

当前代码段

Table View数据源

public override UITableViewCell GetCell (UITableView tableView, NSIndexPath indexPath) 
{
    tableView.RegisterNibForCellReuse(UINib.FromName("summaryListCell", NSBu   ndle.MainBundle), "summaryListCell");
    summaryListCell cell = (summaryListCell)tableView.DequeueReusableCell(new NSString("summaryListCell"), indexPath);
    cell.SetNeedsLayout ();
    return cell;
}

TableView Cell类

using System;
using CoreGraphics;
using Foundation;
using UIKit;
using WBid.WBidiPad.Model;
using WBid.WBidiPad.SharedLibrary;
using System.Linq;
using WBid.WBidiPad.Core;
using System.Collections.Generic;
namespace WBid.WBidiPad.iOS
{
    public partial class summaryListCell : UITableViewCell
    {
        public static readonly UINib Nib = UINib.FromName("summaryListCell", NSBundle.MainBundle);
        public static readonly NSString Key = new NSString("summaryListCell");
        public summaryListCell(IntPtr handle) : base(handle)
        {                        
            laySubViews (this);       
        }
        public static summaryListCell Create()
        {
            summaryListCell cell = (summaryListCell)Nib.Instantiate(null, null)[0];
            return cell;
        }
        public static  void laySubViews(summaryListCell cell)
        {
            Console.WriteLine (cell);
            UIImageView imgBack = new UIImageView();
            imgBack.Frame = new CGRect (0, 0, 900, 50);
            imgBack.Tag = 1010;
            cell.ContentView.AddSubview(imgBack);
        }
    }
}

经过大量的思考和研究,我对代码做了一些修改。在初始化单元格后,我调用了layout subviews()类。请在

下面找到代码

修改后的代码段

Table View数据源

public override UITableViewCell GetCell (UITableView tableView, NSIndexPath indexPath)
{
    tableView.RegisterNibForCellReuse(UINib.FromName("summaryListCell", NSBu   ndle.MainBundle), "summaryListCell");
     summaryListCell cell = (summaryListCell)tableView.DequeueReusableCell(new NSString("summaryListCell"), indexPath);
     // Added layoutsubview calling after initialization   
     cell.laySubViews(cell);        
     cell.SetNeedsLayout ();
     return cell;
 }

TableView Cell类

using System;
using CoreGraphics;
using Foundation;
using UIKit;
using WBid.WBidiPad.Model;
using WBid.WBidiPad.SharedLibrary;
using System.Linq;
using WBid.WBidiPad.Core;
using System.Collections.Generic;
namespace WBid.WBidiPad.iOS
{
    public partial class summaryListCell : UITableViewCell
    {
        public static readonly UINib Nib = UINib.FromName("summaryListCell", NSBundle.MainBundle);
        public static readonly NSString Key = new NSString("summaryListCell");
        public summaryListCell(IntPtr handle) : base(handle)
        {    
            // Removed the layoutsubview calling method                    
            // laySubViews(this);       
        }
        public static summaryListCell Create()
        {
            summaryListCell cell = (summaryListCell)Nib.Instantiate(null, null)[0];
            return cell;
        }
        // Changed the static property from laySubViews method
        public void laySubViews(summaryListCell cell)
        {
            Console.WriteLine (cell);
            UIImageView imgBack = new UIImageView();
            imgBack.Frame = new CGRect (0, 0, 900, 50);
            imgBack.Tag = 1010;
            cell.ContentView.AddSubview(imgBack);
        }
    }
}

通过上述修改,代码片段可以在iOS 8和iOS 9中工作。

我们在TableView中加载了400行(这只是一个数字,我们在动态加载TableView)现在TableView的滚动性能有个问题。滚动TableView时,TableView挂起。

你能给我一个同时适用于iOS 8和iOS 9的解决方案吗?

请查看下面的系统详细信息。我们正在设备上测试iOS 9,我们在下面的配置中部署应用程序,我们使用这个配置得到了确切的崩溃错误(我们在这个配置中得到的错误与我们从app Store下载的应用程序得到的错误相同)

=== ====== ====== Xamarin的工作室 ====== ====== ===

Version 5.9.3 (build 1)d1449294-29ae-49f6-ab88-23f11a709f17运行时:Mono 4.0.1((detached/ed1d3ec) GTK+ 2.24.23 (Raleigh theme)

软件包版本:400010044

=== Apple Developer Tools ===

Xcode 6.3 (7569) Build 6D570

= = = Xamarin的。iOS = = =

Version: 8.10.1.64 (Business Edition) Hash: e6ebd18 Branch: master构建日期:2015-05-21 21:55:09-0400

=== Build Information ===

发布ID: 5090300015a524e1726ed103fdd4fe37e0356f2b35466ce9d构建日期:2015-06-0216:35:08-04 Xamarin添加:51957cfbd06be911b212671ad052c6221ac90f9

===操作系统===

Mac OS X 10.10.3local 14.3.0达尔文内核版本14.3.0PDT 2015年3月23日星期一11:59:05根:xnu-2782.20.48 ~ 5/RELEASE_X86_64 x86_64

=== ====== ====== ====== ====== ====== ===

你能给我们一个解决这个问题的办法吗?

tableView滚动问题xamarin

  1. 调用tableView.RegisterNibForCellReuse在viewDidLoad一次。无需每次获得cell时都注册
  2. 不需要调用cell. laySubViews(cell);cell.SetNeedsLayout ();。我看不出你为什么需要那样做。

问题在于Xamarin。iOS和我更新了Xamarin。iOS最新稳定版本8.10.4.46。现在它在iOS8和ios9上运行得很好。我没有改变任何代码片段。现在我正在使用上面提到的第一个代码片段。