1

这个错误实际上也出现在我自己的应用程序中,但我想我只是参考KittenView_Mac项目中的相同问题。

如果我在 iPhone 6.0/6.1 Emulator 上运行该项目,一切正常。如果我在 5.1 上运行它,它会在尝试绑定 xib 文件中的自定义表格单元格时崩溃。错误是:

[UITableView dequeueReusableCellWithIdentifier:forIndexPath:]: unrecognized selector sent to instance 0xb4a3200

如果我在 4.3 上运行它,我会得到:

[UITableView registerNib:forCellReuseIdentifier:]: unrecognized selector sent to instance 0x7c6a200

我需要改变什么才能让它工作吗?

4

2 回答 2

1

MvvmCross 正式支持 iOS 6.0 及更高版本 - 目前占所有 iOS 设备的 90% 以上 - http://stats.unity3d.com/mobile/index-ios.html

然而,大多数 MvvmCross 在 iOS5 上都可以工作——这使我们达到了所有 iOS 设备的 98.5%。

如果您想获得在 iOS4 和更早版本上工作的支持,那么您将需要避免一些领域 - 包括registerNib:forCellReuseIdentifier(我猜!)在 iOS4 之后引入的这个。

为了使这项工作,您需要编写自己的与 iOS4 兼容的 TableViewSource 代码,它将直接创建新单元格,而不是依赖此registerNibapi。

为此,您可以使用自己的自定义TableViewSource继承MvxTableViewSource- 例如:

 public class MyTableViewSource : MvxTableViewSource
 {
    public MyTableViewSource(UITableView tableView)
        : base(tableView)
    {
    }

    protected override UITableViewCell GetOrCreateCellFor(UITableView tableView, NSIndexPath indexPath, object item)
    {
        var existing = (UITableViewCell)tableView.DequeueReusableCell(KittenCell.CellIdentifier);
        if (existing != null)
            return existing;

        return KittenCell.Create();
    }
 }
于 2013-08-09T16:35:17.930 回答
0

首先,我必须感谢 Stuart 引导我朝着正确的方向前进。我不知道是什么[UITableView dequeueReusableCellWithIdentifier:forIndexPath:]意思——没有 Obj-C 的背景——现在我意识到它的意思是“我找不到那个方法!”

代码中的这一行:

return (UITableViewCell)TableView.DequeueReusableCell(cellIdentifier, indexPath);

要使用 iOS 5,需要成为:

return (UITableViewCell)TableView.DequeueReusableCell(cellIdentifier);

这样它就可以实际执行该方法 - 但后来 iOS 告诉我 nib 文件无效。所以感谢这篇文章https://stackoverflow.com/a/15019273/31902我找到了我的解决方案 - 需要使 xib 文件与早期版本的 iOS 兼容!

现在,这似乎使 4.3 崩溃,但根据 Stuart 的评论,我对我的应用程序在 98.5% 的 iOS 设备上运行感到满意。

于 2013-08-10T03:28:28.307 回答