本文介绍了编译适用于iOS 6和iOS 7的应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很难编译一个iPad应用程序,以便在iOS 6和iOS 7上使用。

I'm struggling to compile an iPad app for use on iOS 6 and iOS 7.

这是我一直得到的消息:

Here's the message I keep getting:

Property 'barTintColor' not found on object of type 'UITabBar *'; did you mean 'tintColor'?

设定目标的 Base SDK 最新iOS(iOS 7.0) iOS部署目标 iOS 6.0 。我在项目上做了一个Clean。

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.

以下是代码:

在.h文件中:

@property (nonatomic, strong) IBOutlet UITabBar *tabbedBar;

在.m文件中:

if ([tabbedBar respondsToSelector: @selector(barTintColor)]) {
     tabbedBar.barTintColor = [UIColor blackColor];
}

我正在编译iOS 7 SDK,所以它应该知道barTintColor 。知道问题可能是什么吗?

I'm compiling against the iOS 7 SDK, so it should know about barTintColor. Any idea what the problem could be?

更新:

好的,我我正在取得进展,但不太了解原因。

Okay, I'm making progress, but not quite understanding why.

请参阅此Xcode截图。请注意Active Scheme选择中我的iPad 3的两个条目。有什么不同?如果我选择顶部选项,我会收到错误。如果我选择底部选项,它可以工作。

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.

任何人都可以解释为什么同一设备在此列表中出现两次,以及为什么它在我选择一个而不是另一个时有效?仅供参考,该设备已安装iOS 6.

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.

推荐答案

您的Xcode中安装了两个SDK:适用于iOS 6和iOS 7。现在,当发生这种情况时,如果您插入iOS 7设备,它会在设备选择器中显示为两个设备(即选项):第一行用于iPad 3(iOS 6),第二行用于iPad 3(iOS 7)。

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).

您的错误问题在于,当您选择iPad 3(iOS 6)时,Xcode仍然将设备读取为设备为iOS 7(那就是它安装了什么,无论如何)所以在构建它时通过 [tabbedBar respondsToSelector:@selector(barTintColor)] 代码(它响应选择器,'因为嘿,它是iOS 7),但因为你正在为iOS 6构建,同时它会引发错误,因为嘿,iOS 6没有这种方法!有趣。

The problem with your error is that when you select iPad 3 (iOS 6), Xcode still reads the 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.

基本上,在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.

编辑:您可以通过以下方式测试我所说的内容 - 而不是使用 respondsToSelector:使用

You can test what I'm saying in the following manner — instead of using respondsToSelector: use

if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0f) {
    // code
}

然后选择列表中的第一个设备(iPad 3 iOS 6)。你会看到你通过 if 子句,但Xcode会给你一个错误,指出选择器在iOS 6上不可用。

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.

这篇关于编译适用于iOS 6和iOS 7的应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 09:17