Tôi đã thiết lập một UITabBarController với hai tab, một là một UIViewController đơn giản và khác là một UINavigationController sử dụng một UIViewController thứ hai như rootController của nó (sau này sẽ được sử dụng để thiết lập một UITableView). Câu hỏi của tôi là liên quan với để đặt tên cho các tab (ví dụ: thiết lập các tiêu đề của mỗi UITabBarItem)Đặt tiêu đề UITabBarItem từ UINavigationController?
Đối với tab đầu tiên (UIViewController đơn giản) Tôi đã thêm như sau (xem bên dưới) sang điều khiển init phương pháp.
// FROM -[MapController init]
- (id)init {
self = [super init];
if(self) {
UITabBarItem *tabBarItem = [self tabBarItem];
[tabBarItem setTitle:@"ONE"];
}
return self;
}
Đối với tab khác tôi đã thêm (xem bên dưới) vào bộ điều khiển thứ hai init (rootController).
// FROM -[TableController init]
- (id)init {
self = [super init];
if(self) {
UITabBarItem *tabBarItem = [[self navigationController] tabBarItem];
[tabBarItem setTitle:@"TWO"];
}
return self;
}
Tôi thiết lập các tiêu đề tabBarItem thứ hai ở đúng nơi như hiện nay nó không hiển thị, khi tôi chạy ứng dụng tab đầu tiên nói "ONE" thứ hai là trống. Ngoài ra tabBarItem (ở trên) cho thấy nil khi tôi in giá trị hoặc xem qua trình gỡ lỗi.
EDIT_001: Nhập mã đầy đủ từ appdelegate
tôi một cách chính xác có thể thiết lập UITabBarItem từ bên trong appdelegate khi tôi lần đầu tiên tạo ra các bộ điều khiển, sẵn sàng cho thêm vào UITabBarController. Nhưng tôi thực sự muốn làm điều này trong các phương thức -init điều khiển riêng biệt cho sự gọn gàng.
// UITabBarController
UITabBarController *tempRoot = [[UITabBarController alloc] init];
[self setRootController:tempRoot];
[tempRoot release];
NSMutableArray *tabBarControllers = [[NSMutableArray alloc] init];
// UIViewController ONE
MapController *mapController = [[MapController alloc] init];
[tabBarControllers addObject:mapController];
[mapController release];
// UITableView TWO
TableController *rootTableController = [[TableController alloc] init];
UINavigationController *tempNavController = [[UINavigationController alloc] initWithRootViewController:rootTableController];
[rootTableController release];
[tabBarControllers addObject:tempNavController];
[tempNavController release];
[rootController setViewControllers:tabBarControllers];
[tabBarControllers release];
[window addSubview:[rootController view]];
[window makeKeyAndVisible];
EDIT_002: Giải pháp cho đến nay, Update UITabBarItems trong ứng dụng của đại biểu ví dụ
// TABLE CONTROLLER
TableController *tableController = [[TableController alloc] init];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:tableController];
[tableController release];
[tabBarControllers addObject:navController];
UITabBarItem *tabBarItem_002 = [navController tabBarItem];
[tabBarItem_002 setTitle:@"TWO"];
[tabBarItem_002 setImage:[UIImage imageNamed:@"GT_TWO.png"]];
[navController release];
EDIT_003: là có một cách để thiết lập các UITabBarItem trong UINavigationController hoặc là các đại biểu (như nó có vẻ) thực sự là nơi tốt nhất để làm điều đó.
self.navigationController.tabBarItem = tabBarItem là những gì làm việc cho tôi trong trường hợp bất cứ ai muốn thử một giải pháp khác! – Rabiees