배경을 한 번 설정할 수는 있지만 그 후에는 결코 다시 변경되지 않습니다. 나는 stackoverflow에 모든 예제를 보았다. 코드 예제는 항상 동일하게 보입니다. 나는 대의원을 정했다. 이미지는 모두 괜찮습니다. 나는 그들을 기본 이미지로 차례대로 설정하고 보여줄 것이다. 그러나 앱 실행이 끝난 후에는 더 이상 백그라운드에서 아무 일도 일어나지 않습니다.TabBar의 setBackgroundImage가 항목을 탭할 때 작동하지 않습니다.
이- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[self customizeInterface];
// Override point for customization after application launch.
self.tabController = (UITabBarController *)self.window.rootViewController;
self.tabController.delegate = self;
...
}
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
int tabitem = self.tabController.selectedIndex;
NSLog(@"tabitem: %i", tabitem);
[self switchTabBarImage:tabitem];
//[[tabController objectAtIndex:tabitem] popToRootViewControllerAnimated:YES];
}
- (void)switchTabBarImage:(int)selectedIndex
{
NSLog(@"selected: %i", selectedIndex);
if (selectedIndex == 0) {
NSLog(@"0");
UIImage *tabBarBackground = [UIImage imageNamed:@"tabbar-1.png"];
[[UITabBar appearance] setBackgroundImage:tabBarBackground];
}
if (selectedIndex == 1) {
NSLog(@"1");
UIImage *tabBarBackground = [UIImage imageNamed:@"tabbar-2.png"];
[[UITabBar appearance] setBackgroundImage:tabBarBackground];
}
if (selectedIndex == 2) {
NSLog(@"2");
UIImage *tabBarBackground = [UIImage imageNamed:@"tabbar-3.png"];
[[UITabBar appearance] setBackgroundImage:tabBarBackground];
}
if (selectedIndex == 3) {
NSLog(@"3");
UIImage *tabBarBackground = [UIImage imageNamed:@"tabbar-4.png"];
[[UITabBar appearance] setBackgroundImage:tabBarBackground];
}
}
- (void)customizeInterface
{
UIImage *tabBarBackground = [UIImage imageNamed:@"tabbar-1.png"];
[[UITabBar appearance] setBackgroundImage:tabBarBackground];
UIImage *selectionIndicator = [UIImage imageNamed:@"tabbar-icon-clean.png"];
[[UITabBar appearance] setSelectionIndicatorImage:selectionIndicator];
}
디버거를 보여줍니다 : 나는 검색도 시간과 번만 작동 이유를 알아낼 수있어
2012-11-13 02:42:06.147 soundapp[9060:c07] tabitem: 1
2012-11-13 02:42:06.148 soundapp[9060:c07] selected: 1
2012-11-13 02:42:06.148 soundapp[9060:c07] 1
2012-11-13 02:42:07.739 soundapp[9060:c07] tabitem: 2
2012-11-13 02:42:07.739 soundapp[9060:c07] selected: 2
2012-11-13 02:42:07.740 soundapp[9060:c07] 2
여기 내 코드입니다. 아무도 내 코드에서 실수를 보지 않습니까?