[英]tableView Scrolling issue Xamarin.ios
我们正在iOS 9(测试版)设备中测试我们的应用程序。 加载表视图时,应用程序崩溃。 但是相同的代码在iOS 8中执行良好。
请在下面找到代码
当前代码段
表格视图数据源
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单元格类
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()类。 请在下面找到代码
修改后的代码段
表格视图数据源
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单元格类
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 Studio ====== ==========
版本5.9.3(内部版本1)安装UUID:d1449294-29ae-49f6-ab88-23f11a709f17运行时:Mono 4.0.1((detached / ed1d3ec)GTK + 2.24.23(Raleigh主题)
封装版本:400010044
=== Apple开发人员工具===
Xcode 6.3(7569)内部版本6D570
=== Xamarin.iOS ===
版本:8.10.1.64(商业版)哈希:e6ebd18分支:master生成日期:2015-05-21 21:55:09-0400
===生成信息===
发行ID:509030001 Git修订版:5a524e1726ed103fdd4fe37e0356f2b35466ce9d构建日期:2015-06-02 16:35:08-04 Xamarin插件:51957cfbd06be911b212671ad05c2c6221ac90f9
===操作系统===
Mac OS X 10.10.3 Darwin Deepaks-Mac.local 14.3.0 Darwin Kernel Version 14.3.0 Mon Mar 23 11:59:05 PDT 2015 root:xnu-2782.20.48〜5 / RELEASE_X86_64 x86_64
=== =================================
您能给我们解决这种情况的方法吗?
tableView.RegisterNibForCellReuse
。 每次获得手机时都无需注册 cell. laySubViews(cell);
cell. laySubViews(cell);
和cell.SetNeedsLayout ();
是多余的。 我看不出您为什么需要这样做的任何理由。 问题出在Xamarin.iOS,我更新了Xamarin.iOS最新的稳定版本8.10.4.46。 现在,它可以在iOS8和iOS 9中完美运行。 我没有更改任何代码段。 现在,我正在使用上面提到的第一个代码段。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.