을 내에 추가하는 방법이 있는지 궁금합니다. 런타임에있을 필요는 없습니다.추가 UITabbarItem을 UITabbarController에 추가하기
내가하고 싶은 것은이 버튼을 눌렀을 때 실제로 볼 수있는 ViewController 위에있는 presentModalViewController:
을 원하고 TabBarController 또는 컨트롤러 중 하나 여야합니다.
바라기를 바란다면 충분합니다. 그렇지 않다면 언제든지 물어보십시오.
을 내에 추가하는 방법이 있는지 궁금합니다. 런타임에있을 필요는 없습니다.추가 UITabbarItem을 UITabbarController에 추가하기
내가하고 싶은 것은이 버튼을 눌렀을 때 실제로 볼 수있는 ViewController 위에있는 presentModalViewController:
을 원하고 TabBarController 또는 컨트롤러 중 하나 여야합니다.
바라기를 바란다면 충분합니다. 그렇지 않다면 언제든지 물어보십시오.
내 연구 결과로 UITabBarItem을 UITabBarController가 관리하는 UITabBar에 추가 할 수 없습니다.
사전 조건 : 지금 표시됩니다으로
당신은 어쩌면 뷰 컨트롤러의 목록을 추가하여 UITabBarItem을 추가 한 이후,이 또한 더 사용자 정의 UITabBarItems를 추가하는 선택의 방법입니다 당신이 UITabB를 추가하는 방법을 알고 있기 때문에 지금 :
tabbarController = [[UITabBarController alloc] init]; // tabbarController has to be defined in your header file
FirstViewController *vc1 = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:[NSBundle mainBundle]];
vc1.tabBarItem.title = @"First View Controller"; // Let the controller manage the UITabBarItem
SecondViewController *vc2 = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:[NSBundle mainBundle]];
vc2.tabBarItem.title = @"Second View Controller";
[tabbarController setViewControllers:[NSArray arrayWithObjects: vc1, vc2, nil]];
tabbarController.delegate = self; // do not forget to delegate events to our appdelegate
추가 지정 UITabBarItems : 내가 전에 언급 한 바와 같이, 당신은 아마 뷰 컨트롤러의 목록을 추가하여 UITabBarItems을 추가 한 뷰 컨트롤러를 추가를 통해 arItems은 또한 사용자 정의 UITabBarItems를 추가하는 같은 방법을 사용할 수 있습니다
UIViewController *tmpController = [[UIViewController alloc] init]; tmpController.tabBarItem.title = @"Custom TabBar Item"; // You could also add your custom image: // tmpController.tabBarItem.image = [UIImage alloc]; // Define a custom tag (integers or enums only), so you can identify when it gets tapped: tmpController.tabBarItem.tag = 1;
는 위의 줄을 수정 : [tabbarController setViewControllers:[NSArray arrayWithObjects: vc1, vc2, tmpController, nil]];
[tmpController release]; // do not forget to release the tmpController after adding to the list
모든, 지금 당신은 당신의 TabBar의에서 사용자 정의 버튼을 잘해야합니다.
이 사용자 정의 UITabBarItem의 이벤트를 처리하는 방법은 무엇입니까?
쉬운,보기 :
은 AppDelegate에 클래스 (또는 tabbarController을 들고 클래스)에 UITabBarControllerDelegate를 추가합니다.@interface YourAppDelegate : NSObject <UIApplicationDelegate, UITabBarControllerDelegate> { }
이 기능을 추가하여 프로토콜 정의를 맞추기 : - (void)tabBarController:(UITabBarController *)theTabBarController didSelectViewController:(UIViewController *)viewController {
NSUInteger indexOfTab = [theTabBarController.viewControllers indexOfObject:viewController];
UITabBarItem *item = [theTabBarController.tabBar.items objectAtIndex:indexOfTab];
NSLog(@"Tab index = %u (%u), itemtag: %d", indexOfTab, item.tag);
switch (item.tag) {
case 1:
// Do your stuff
break;
default:
break;
}
}
이제 생성하고 사용자 정의 UITabBarItems를 처리 할 필요가 있습니다. 희망이 도움이됩니다. 재미있게 보내세요 ....