从UITabBar调用setUnselectedItemTintColor时崩溃应用程序

Jar*_*Chu 2 objective-c uitabbar ios

我已尝试过两条线,但这一切都导致[UITabBar setUnselectedItemTintColor:]:无法识别的选择器发送到实例

[self.tabBar setUnselectedItemTintColor:[UIColor blackColor]];
[[UITabBar appearance] setUnselectedItemTintColor:[UIColor blackColor]];
Run Code Online (Sandbox Code Playgroud)

有什么建议吗?

ale*_*nik 8

此方法仅适用于iOS 10,因此在以前的版本中会崩溃.您应该在调用之前检查方法可用性.

 if ([[UITabBar appearance] respondsToSelector:@selector(setUnselectedItemTintColor:)]) {
     [[UITabBar appearance] setUnselectedItemTintColor:[UIColor blackColor]];
 }
Run Code Online (Sandbox Code Playgroud)