xcode 编译适用于 iOS 6 和 iOS 7 的应用程序
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19009538/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Compiling an app that works in iOS 6 and iOS 7
提问by Axeva
I'm struggling to compile an iPad app for use on iOS 6 and iOS 7.
我正在努力编译用于 iOS 6 和 iOS 7 的 iPad 应用程序。
Here's the message I keep getting:
这是我不断收到的消息:
Property 'barTintColor' not found on object of type 'UITabBar *'; did you mean 'tintColor'?
The Base SDK
for the target is set to Latest iOS (iOS 7.0)
, and the iOS Deployment Target
is iOS 6.0
. I did a Clean on the project.
将Base SDK
目标设定为Latest iOS (iOS 7.0)
,且iOS Deployment Target
是iOS 6.0
。我对项目进行了清理。
Here is the code:
这是代码:
In the .h file:
在 .h 文件中:
@property (nonatomic, strong) IBOutlet UITabBar *tabbedBar;
In the .m file:
在 .m 文件中:
if ([tabbedBar respondsToSelector: @selector(barTintColor)]) {
tabbedBar.barTintColor = [UIColor blackColor];
}
I'm compiling against the iOS 7 SDK, so it should know about barTintColor. Any idea what the problem could be?
我正在针对 iOS 7 SDK 进行编译,因此它应该了解 barTintColor。知道可能是什么问题吗?
Updated:
更新:
Okay, I'm making progress, but not quite understanding why.
好的,我正在取得进展,但不太明白为什么。
See this Xcode screenshot. Note the two entries for my iPad 3 in the Active Scheme selection. What is the difference? If I choose the top option, I get the error. If I choose the bottom option, it works.
请参阅此 Xcode 屏幕截图。请注意 Active Scheme 选项中我的 iPad 3 的两个条目。有什么不同?如果我选择最上面的选项,我会收到错误消息。如果我选择底部选项,它会起作用。
Can anyone explain why the same device appears twice in this list, and why it works when I choose one and not the other? FYI, the device has iOS 6 installed.
谁能解释为什么同一个设备在这个列表中出现两次,以及为什么当我选择一个而不是另一个时它会起作用?仅供参考,该设备已安装 iOS 6。
回答by nikolovski
You have two SDKs installed in your Xcode: for iOS 6 and iOS 7. Now, when that happens, if you plug in your iOS 7 device, it shows as two devices (i.e. options) in the device selector: first row is for iPad 3 (iOS 6), second for iPad 3 (iOS 7).
您的 Xcode 中安装了两个 SDK:用于 iOS 6 和 iOS 7。现在,如果发生这种情况,如果您插入 iOS 7 设备,它会在设备选择器中显示为两个设备(即选项):第一行用于 iPad 3 (iOS 6),第二个是 iPad 3 (iOS 7)。
The problem with your error is that when you select iPad 3 (iOS 6), Xcode still readsthe device as iOS 7 (and that's what it has installed, anyway) so when building it passes the [tabbedBar respondsToSelector: @selector(barTintColor)]
code (it responds to the selector, 'cause hey, it's iOS 7), but because you're building for iOS 6, at the same time it raises an error, 'cause hey, iOS 6 doesn't have that method! Fun.
您的错误的问题在于,当您选择 iPad 3 (iOS 6) 时,Xcode 仍将设备读取为 iOS 7(无论如何,这就是它已安装的设备),因此在构建它时会传递[tabbedBar respondsToSelector: @selector(barTintColor)]
代码(它响应选择器,'因为嘿,它是 iOS 7),但是因为你是为 iOS 6 构建的,同时它会引发一个错误,因为嘿,iOS 6 没有那个方法!乐趣。
Basically, you can't use the iOS 6 option when testing on the iOS 7 device. You either need a iOS 6 device, or you're stuck with the simulator for testing old versions.
基本上,在 iOS 7 设备上测试时不能使用 iOS 6 选项。您要么需要 iOS 6 设备,要么使用模拟器来测试旧版本。
EDIT: You can test what I'm saying in the following manner — instead of using respondsToSelector:
use
编辑:您可以通过以下方式测试我所说的内容 - 而不是使用respondsToSelector:
use
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0f) {
// code
}
and then select the first device in the list (iPad 3 iOS 6). You'll see that you go through the if
clause, but Xcode gives you an error that the selector isn't available on iOS 6.
然后选择列表中的第一个设备(iPad 3 iOS 6)。您会看到您已经完成了该if
子句,但 Xcode 会提示您选择器在 iOS 6 上不可用的错误。