1

My app running perfectlly in iOS 5.1 and iOS 6.1. But wheen I try to run it on iOS 4.3 than it was crahing on this code:

 [self.tabBarItem setFinishedSelectedImage:[UIImage imageNamed:@"home-active.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"home-normal"]];

I'm using this code to seting image on TabBar.

This is my log information.

2013-03-08 15:16:27.688 GrandNatural[3372:12c03] -[UITabBarItem setFinishedSelectedImage:withFinishedUnselectedImage:]: unrecognized selector sent to instance 0x628c090
2013-03-08 15:16:27.690 GrandNatural[3372:12c03] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UITabBarItem setFinishedSelectedImage:withFinishedUnselectedImage:]: unrecognized selector sent to instance 0x628c090'
*** Call stack at first throw:
(
    0   CoreFoundation                      0x019785a9 __exceptionPreprocess + 185
    1   libobjc.A.dylib                     0x016e7313 objc_exception_throw + 44
    2   CoreFoundation                      0x0197a0bb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
    3   CoreFoundation                      0x018e9966 ___forwarding___ + 966
    4   CoreFoundation                      0x018e9522 _CF_forwarding_prep_0 + 50
    5   GrandNatural                        0x0000f8fe -[HomeViewController initWithNibName:bundle:] + 535
    6   GrandNatural                        0x00002985 -[GrandNaturalAppDelegate application:didFinishLaunchingWithOptions:] + 262
    7   UIKit                               0x00ce5c89 -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1163
    8   UIKit                               0x00ce7d88 -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 439
    9   UIKit                               0x00cf2617 -[UIApplication handleEvent:withNewEvent:] + 1533
    10  UIKit                               0x00ceaabf -[UIApplication sendEvent:] + 71
    11  UIKit                               0x00ceff2e _UIApplicationHandleEvent + 7576
    12  GraphicsServices                    0x021dd992 PurpleEventCallback + 1550
    13  CoreFoundation                      0x01959944 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
    14  CoreFoundation                      0x018b9cf7 __CFRunLoopDoSource1 + 215
    15  CoreFoundation                      0x018b6f83 __CFRunLoopRun + 979
    16  CoreFoundation                      0x018b6840 CFRunLoopRunSpecific + 208
    17  CoreFoundation                      0x018b6761 CFRunLoopRunInMode + 97
    18  UIKit                               0x00ce77d2 -[UIApplication _run] + 623
    19  UIKit                               0x00cf3c93 UIApplicationMain + 1160
    20  GrandNatural                        0x00002856 main + 132
    21  GrandNatural                        0x00002795 start + 53
)
terminate called throwing an exception(lldb) 
JiteshW
  • 2,195
  • 4
  • 32
  • 61
  • Its like the dump says. It does not recognise the setFinishedSelectImage method as it was introduced in version 5 of the API. What you can do in your code is use SELECTORS and specifically respondsToSelector to see if the object has the method available. – Bushbert Mar 08 '13 at 09:56
  • check this :-http://stackoverflow.com/questions/8939399/tabbar-item-image-and-selectedimage – Nitin Gohel Mar 08 '13 at 10:18

2 Answers2

3

You can set image on tabbar using this code :

if ([[[UIDevice currentDevice] systemVersion] floatValue]<5.0)
{  
   self.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"your name" image:[UIImage imageNamed:@"home-normal"] tag:0];
}
else
{
   self.tabBarItem = [[UITabBarItem alloc] init];
   self.tabBarItem.title = @"your name";
   [self.tabBarItem setFinishedSelectedImage:[UIImage imageNamed:@"home-active"] withFinishedUnselectedImage:[UIImage imageNamed:@"home-normal"]];
}
Dilip Manek
  • 9,095
  • 5
  • 44
  • 56
2

Ok, go to the documentation page for UITabBarItem, find that method, and tell me what it says under Availability

I'll give you a hint: 4.3 is not valid.

borrrden
  • 33,256
  • 8
  • 74
  • 109
  • oh yes, it says "Availability:Available in iOS 5.0 and later." than can you help me on how can i achieve this for iOS 4.3 –  Mar 08 '13 at 10:02
  • Have a look here. http://stackoverflow.com/questions/13245898/tabbar-customization-in-ios-4 – Bushbert Mar 08 '13 at 10:05
  • But for use that code i have to detect first which os on my app is running any suggestion on os detection –  Mar 08 '13 at 10:08
  • Do your homework, that question has been answered many times on stack overflow – borrrden Mar 08 '13 at 10:12
  • can i able to restrict my app to use on 3rd Generation mobile and only work for iOS > 5.0? –  Mar 08 '13 at 10:48