2012-04-24 12 views
0

iPhone 4.3シミュレータでこのコードを使用したとき、このエラーが発生しましたが、iPhone 5シミュレータで実行すると、エラーなしで動作します。TabbarControllerの色調の色

コード

UITabBarController *tabB = [[UITabBarController alloc] init]; 
tabB.tabBar.tintColor=[UIColor colorWithRed:124.0/255.0 green:150.0/255.0 blue:32.0/255.0 alpha:1.0]; 

tabB.tabBar.selectedImageTintColor=[UIColor colorWithRed:187.0/255.0 green:255.0/255.0 blue:38.0/255.0 alpha:1.0];    
tabB.viewControllers = [NSArray arrayWithObjects:hc,bt, nil]; 
[self.navigationController pushViewController:tabB animated:YES]; 

エラー

-[UITabBar setTintColor:]: unrecognized selector sent to instance 0x78787c0 
2012-04-24 10:59:46.776 welcomeKidsWebsite[10357:12203] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UITabBar setTintColor:]: unrecognized selector sent to instance 0x78787c0' 
*** Call stack at first throw: 
(
    0 CoreFoundation      0x01bcd5a9 __exceptionPreprocess + 185 
    1 libobjc.A.dylib      0x01d21313 objc_exception_throw + 44 
    2 CoreFoundation      0x01bcf0bb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187 
    3 CoreFoundation      0x01b3e966 ___forwarding___ + 966 
    4 CoreFoundation      0x01b3e522 _CF_forwarding_prep_0 + 50 
    5 welcomeKidsWebsite     0x0005ac8e -[KidsWelcomeViewController GotoBooks:] + 622 
    6 UIKit        0x00e1f4fd -[UIApplication sendAction:to:from:forEvent:] + 119 
    7 UIKit        0x00eaf799 -[UIControl sendAction:to:forEvent:] + 67 
    8 UIKit        0x00eb1c2b -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 527 
    9 UIKit        0x00eb07d8 -[UIControl touchesEnded:withEvent:] + 458 
    10 UIKit        0x00e43ded -[UIWindow _sendTouchesForEvent:] + 567 
    11 UIKit        0x00e24c37 -[UIApplication sendEvent:] + 447 
    12 UIKit        0x00e29f2e _UIApplicationHandleEvent + 7576 
    13 GraphicsServices     0x02528992 PurpleEventCallback + 1550 
    14 CoreFoundation      0x01bae944 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52 
    15 CoreFoundation      0x01b0ecf7 __CFRunLoopDoSource1 + 215 
    16 CoreFoundation      0x01b0bf83 __CFRunLoopRun + 979 
    17 CoreFoundation      0x01b0b840 CFRunLoopRunSpecific + 208 
    18 CoreFoundation      0x01b0b761 CFRunLoopRunInMode + 97 
    19 GraphicsServices     0x025271c4 GSEventRunModal + 217 
    20 GraphicsServices     0x02527289 GSEventRun + 115 
    21 UIKit        0x00e2dc93 UIApplicationMain + 1160 
    22 welcomeKidsWebsite     0x000024ac main + 188 
    23 welcomeKidsWebsite     0x000023e5 start + 53 
+1

このsetTintColor:はios5に追加されているので、ios4.3には含まれていません。 –

+0

@AalokParikhこれは答えになるはずです。 – jrturton

+0

解決方法はありますか? –

答えて

2

良い方法である:IOS 5では

if ([tabBarController.tabBar respondsToSelector:@selector(setTintColor:)]) { 
     [tabBarController.tabBar setTintColor:color]; 
} 

これはタブバーのtintcolorを設定し、下部であろうバージョンそれはクラッシュしません

-2

documentationtintColorによると、この

tabB.tintColor=[UIColor colorWithRed:124.0/255.0 green:150.0/255.0 blue:32.0/255.0 alpha:1.0]; 
+0

もう一度コードが表示されるエラーが発生しました –

0

を試すのiOS 5でのみ使用可能です。 0以降。ヒントは、4.3シミュレータは基本的にはメソッドが存在しないことを意味するunrecognized selector sent to instanceと言っています。

次のいずれかを実行する必要があります

  • が5.0にあなたの最低限必要なのiOSを設定します。
  • iOS 5.0以上で実行している場合にのみ色合いを適用します。
  • 両方のバージョンでサポートされている代替方法を使用してください。

ドキュメントの抜粋:

tintColor

ティントカラーは、タブバーの背景に適用します。このバージョンの独立を作る @property(保持、非アトミック)UIColor * tintColor状況

Available in iOS 5.0 and later. 
+0

代替方法をご存知ですか? –

+0

私はこれまで、[この投稿](http://stackoverflow.com/questions/3339722/check-iphone-ios-version)のような方法を使って、アプリケーションに応じてiOS 5のみのユーザーに色合いを有効にしました実行可能ではない可能性があります。 – GregularExpressions

関連する問題