gpt4 book ai didi

ios - 选择器 'indexPathForRow:inSection:' 没有已知的类方法

转载 作者:行者123 更新时间:2023-11-28 14:45:47 25 4
gpt4 key购买 nike

我正在尝试导入/使用 this我的 Swift 应用程序中的项目,但编译器抛出大量错误并显示以下消息:

No known class method for selector 'indexPathForRow:inSection:'

以下是产生上述错误的典型代码:

if ([self tileForIndexPath:[NSIndexPath indexPathForRow:row inSection:i]].empty) {
...
}

不过,我可以将下载的项目作为独立应用程序运行,没有任何问题。

我还将所有框架添加到我的主应用程序中 - 这些框架已被使用并安装到所述项目中,但这没有帮助。我的主要项目的部署目标是 10.0。

最佳答案

indexPathForRow:inSection:是创建 NSIndexPath 实例的静态构造方法。它在 UIKit 中定义:

https://developer.apple.com/documentation/foundation/nsindexpath/1614934-indexpathforrow?language=objc

在这个项目中作者在pch文件中引入了UIKit:

https://github.com/austinzheng/iOS-2048/blob/7c0840a0f7bd77b01d6a36778a253f8f4b2e6529/NumberTileGame/NumberTileGame/NumberTileGame-Prefix.pch#L14

因此您有 2 个选择:在您的项目中为 Objective-C 代码设置一个 pch 文件(创建文件并添加到 Xcode 项目build设置),或者在出现此错误的每个源文件中添加 #import <UIKit/UIKit.h> .

关于ios - 选择器 'indexPathForRow:inSection:' 没有已知的类方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50267677/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com