iOS-UITABarViewController 요약
UItabBarController는 UINavigationController와 유사하다. UItabBarController는 여러 개의 컨트롤러를 쉽게 관리하고 컨트롤러 간의 전환을 쉽게 완성할 수 있다. 전형적인 예는 QQ, 위챗 등이다.하지만.전자는 관리하는 보기가 계속 존재하지만 후자는 팝 후에 메모리를 없애고 방출한다.
주의: UITABarController는 보통 프로그램 전체의 루트 ViewController이며, 다른 container view Controller에 추가할 수 없습니다.
2. UITABarController의 사용:
1. 사용 단계:
(1) UITABarController 초기화
(2) UIWindow의 rootViewController를 UItabBarController로 설정
(3) 상응하는 하위 컨트롤러 만들기 (viewcontroller)
(4) UITABarController에 하위 컨트롤러 추가
2. 코드 예
새 빈 UITABarController, 컨트롤러에서 인코딩
-(void) viewDidLoad {
MapViewController *v1 = [MapViewControllernew];
v1.tabBarItem.image = [UIImageimageNamed:@"icon_map"];
v1.tabBarItem.title = @" ";
v1.view.backgroundColor = [UIColororangeColor];
CycleViewController *v2 = [CycleViewControllernew];
v2.tabBarItem.image = [UIImageimageNamed:@"icon_cycle"];
v2.tabBarItem.title = @" ";
v2.view.backgroundColor = [UIColorgreenColor];
OtherViewController *v3 = [OtherViewControllernew];
v3.tabBarItem.image = [UIImageimageNamed:@"icon_other"];
v3.tabBarItem.title = @" ";
v3.view.backgroundColor = [UIColoryellowColor];
MineViewController *v4 = [MineViewControllernew];
v4.tabBarItem.image = [UIImageimageNamed:@"icon_user"];
v4.tabBarItem.title = @" ";
v4.view.backgroundColor = [UIColorredColor];
UINavigationController *n1 = [[UINavigationControlleralloc] initWithRootViewController:v1];
UINavigationController *n2 = [[UINavigationControlleralloc] initWithRootViewController:v2];
UINavigationController *n3 = [[UINavigationControlleralloc] initWithRootViewController:v3];
UINavigationController *n4 = [[UINavigationControlleralloc] initWithRootViewController:v4];
NSArray *array = @[n1,n2,n3,n4];
self.viewControllers = array;
}
이렇게 하면 네 개의 네비게이션 컨트롤러가 있는tabBarController를 만들 수 있습니다. Appdelegate에서 이 UITbarBarcontroller 컨트롤러를 보기 컨트롤러로 설정하기만 하면 됩니다.
self.window.rootViewController = [[UITbarBarcontroller alloc] init];
중요 설명
1、UITabBar
아래의 도구막대를 UITA Bar라고 하는데 UITA Bar Controller에 N 서브 컨트롤러가 있다면 UITA Bar 내부에 N 개의 UITA Bar Button이 서브 컨트롤러로 대응할 것이다(단 맨 밑에 최대 5개가 표시되고 많으면 마지막 칸에 숨겨져 있어 클릭해서 볼 수 있다).
주의: UITA Bar Button은 UITA Bar에서 차지하는 위치가 균등하고 UITA Bar의 높이는 49이다.
2、UITabBarButton
UItabBarButton은 어떤 내용을 나타낼지 하위 컨트롤러의tabBarItem 속성에 따라 결정합니다
c1.tabBarItem.title=@" ";
c1.tabBarItem.image=[UIImage imageNamed:@"tab_recent_nor"];
UITABarItem 은 다음과 같은 속성으로 UITABarButton 컨텐츠에 영향을 미칩니다.
title (제목), 이미지 (아이콘),selectImage (선택한 아이콘),badgeValue (알림 숫자)
3. UITABarController에 하위 컨트롤러를 추가할 수 있는 두 가지 방법이 있다
(1)[tb addChildViewController:c1];
(2)tb.viewControllers=@[c1,c2,c3,c4];
주의: 전시된 순서와 추가된 순서가 일치하며 내비게이션 컨트롤러와 달리 눈앞에 보이는 것은 첫 번째로 추가된 컨트롤러에 대응하는 View입니다.
3、UITabBarItem -
UITabBarItem *item = [[UITabBarItem alloc] initWithTitle:@"Second" image:nil tag:2];
[item setFinishedSelectedImage:[UIImage imageNamed:@"second"] withFinishedUnselectedImage:[UIImage imageNamed:@"first"]];
viewController2.tabBarItem = item;
4. Change SelectedViewcontroller(현재 선택한 컨트롤러 변경)
UITABarController에 현재 표시된viewController를 변경하려면 다음 두 가지 방법을 사용합니다.
1. selectedIndex 속성
2. selectedViewController 속성
3. viewControllers 속성
view Controllers 속성을 설정하면 현재 선택된view Controller에 영향을 줍니다. 이 속성을 설정할 때 UITA Bar Controller는 오래된 view Controller를 모두 비우고 새view Controller를 배치합니다. 마지막으로 표시된view Controller를 다시 선택하십시오. 이view Controller가 존재하지 않으면 index와selected Index가 같은view Controller를 선택하십시오. 이 index가 잘못되면첫 번째viewController가 기본적으로 선택됩니다.
5.moreNavigationController
more
으로 바뀌고 설정된viewControlles 순서에 따라 앞의 4개의viewController의tabBarItem을 표시하며 뒤의 탭BarItem은 더 이상 표시되지 않습니다.more를 눌렀을 때 표준navigation View Controller가 팝업됩니다. 다른 보이지 않는view Controller가 있고 편집 단추가 있습니다. 이 단추를 누르면 아이팟 프로그램에서 설정한tabBar와 같은 편집 인터페이스에 들어갈 수 있습니다.6. UITABarController의 Rotation
7. UItabBarControllerDelegate
- tabBarController:shouldSelectViewController:
- tabBarController:didSelectViewController:
- (void)tabBarController:(UITabBarController *)tabBarController willBeginCustomizingViewControllers:(NSArray *)viewControllers;
- (void)tabBarController:(UITabBarController *)tabBarController willEndCustomizingViewControllers:(NSArray *)viewControllers changed:(BOOL)changed;
- (void)tabBarController:(UITabBarController *)tabBarController didEndCustomizingViewControllers:(NSArray *)viewControllers changed:(BOOL)changed;
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.