DequeueReuseableCell仅在iPhone 4S上崩溃应用程序

本文关键字:崩溃 应用程序 4S 仅在 iPhone DequeueReuseableCell | 更新日期: 2023-09-27 18:36:24

我正在使用Xamarin + Mvvmcross开发一个应用程序。目前,它在iPad Mini,iPad 2,3,iPhone 5S和6上运行良好。奇怪的是,其中一个视图在运行iOS 4.1的iPhone 7.1S上崩溃。所有测试均使用真实设备完成。

这是崩溃:

https://gist.github.com/nunohorta/2b84245899e8c0daa116

表源的代码是这样的:

    public class MessagesTableSource : MvxStandardTableViewSource
{
    UITableView _tableview;
    MessagesView _parent;
    UILabel messageLabel;
    private static readonly NSString MessageCellIdentifier = new NSString("MessageCell");
    public MessagesTableSource(UITableView tableView, MessagesView parent) : base(tableView)
    {
        _tableview = tableView;
        _parent = parent;
    }
    public override nint RowsInSection (UITableView tableview, nint section)
    {
        return _parent.ViewModel.Messages != null ? _parent.ViewModel.Messages.Count : 0;
    }
    public override nint NumberOfSections (UITableView tableView)
    {
        if (_parent.ViewModel.Messages != null && _parent.ViewModel.Messages.Count > 0) {
            return 1;
        } else {
            /*
             * Custom View here
             * 
             * */
            return 0;
        }
    }

    protected override UITableViewCell GetOrCreateCellFor (UITableView tableView, NSIndexPath indexPath, object item)
    {
        var cell = (MessageCell)tableView.DequeueReusableCell("MessageCell");
        return cell;
    }
}

我还在 viewDidLoad 上注册了这样的自定义类:

    tableView.RegisterNibForCellReuse(UINib.FromName("MessageCell", NSBundle.MainBundle), MessageCellIdentifier);

我不知道为什么它只为一台设备崩溃......崩溃似乎发生在UIKit/CoreFoundation上。

DequeueReuseableCell仅在iPhone 4S上崩溃应用程序



您可能需要将 MessageCell 笔尖注册到自定义 MessageCell 类,就像在视图中加载方法一样。因为这是第一次,它可能找不到带有标识符的单元格。

tableView.registerNib(UINib(nibName: "CustomOneCell", bundle: nil), forCellReuseIdentifier: "CustomCellOne")


使用标识符
对单元格进行分解

tableView.dequeueReusableCellWithIdentifier("CustomCellOne", forIndexPath: indexPath) as! CustomOneCell


我希望它可能有助于解决问题。