11

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'?

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.

Xcode Target Settings

Here is the code:

In the .h file:

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

In the .m file:

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?

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 device selection

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.

4

1 回答 1

15

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

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

基本上,在 iOS 7 设备上进行测试时,您不能使用 iOS 6 选项。您要么需要 iOS 6 设备,要么被困在模拟器上来测试旧版本。

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

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

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

于 2013-09-25T20:26:29.953 回答