Có cách nào để tôi có thể có một UINavigationController
và luôn luôn hiển thị cùng một số UIBarButtonItem
bất kể số lần được đẩy không?UIBarButtonItem không đổi trong UINavigationController
5
A
Trả lời
1
Hãy thử this-
- Tạo lớp con (
CustomNavigationController
) củaUINavigationController
& sử dụng nó để thúc đẩy điều khiển tầm nhìn của bạn. - Trong
CustomNavigationController
tạoUIBarButtonItem
tronginit
hoặc trongviewDidLoad
. Thêmtarget
&action
vào đó. - Thực hiện
UINavigationControllerDelegate
đại biểu trongCustomNavigationController
và đặtbarButtonYouCreated
làm mục nút thanh phải hoặc trái cho mỗi bộ điều khiển chế độ xem theo phương pháp đại biểu.
Sử dụng
- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
viewController.navigationItem.leftBarButtonItem = barButtonYouCreated;
}
hoặc
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
0
Bạn có thể sử dụng UINavigationControllerDelegate
như sau:
- (void)navigationController:(UINavigationController *)navigationController
willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
Và trong phương pháp đại biểu này, bạn có thể kiểm tra thêm một barButtonItem để thanh điều hướng.
0
Bạn có thể tạo ra một thế giới UITabBarController
trong UINavigationController
có chứa bộ điều khiển đẩy bạn, sau đó làm cho bộ điều khiển đẩy bạn navigationbar
ẩn
0
Hoặc thử sử dụng một loại UINavigationController, và tùy chỉnh các mục trở lại, vì vậy dù có bao nhiêu lần nó đẩy , chỉ cần đặt chế độ xem tương tự cho mục sau của navigationController. Một cái gì đó như:
@implementation UIViewController (CustomNavigation)
- (void)setLeftBarButtonItem:(UIButton*)leftview
{
UIBarButtonItem *customItem = [[[UIBarButtonItem alloc] initWithCustomView:leftview] autorelease];
self.navigationItem.leftBarButtonItem = customItem;
[(UIButton*)self.navigationItem.leftBarButtonItem.customView addTarget:self.navigationController action:@selector(popViewControllerAnimated:) forControlEvents:UIControlEventTouchUpInside];
}