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];
}
Các vấn đề liên quan
- 1. UIBarButtonItem không xuất hiện
- 2. Thêm UINavigationController bên trong UIViewController
- 3. Cách thay đổi UIBarButtonItem trong UINavigationBar
- 4. Thêm một UIBarButtonItem làm mới vào một UINavigationController được tải từ một NIB
- 5. Thêm các mục vào NavigationBar (Không sử dụng UINavigationController)
- 6. Thay đổi font chữ của một UIBarButtonItem
- 7. Thay đổi chiều rộng của UIBarButtonItem
- 8. Thay đổi màu bóng UIToolbar cho UIBarButtonItem
- 9. Các bước trong phân lớp UINavigationController
- 10. Thay đổi hoạt ảnh cho UINavigationController NavigationBar
- 11. Cách thay đổi kích cỡ UIBarButtonItem trong mã
- 12. Thay đổi chiều rộng của một UIBarButtonItem trong một UINavigationBar
- 13. Thay đổi hướng UIViewController trong ngăn xếp UINavigationController
- 14. UIToolbar không hiển thị UIBarButtonItem
- 15. sử dụng UINavigationBar mà không cần UINavigationController
- 16. Tránh UIBarButtonItem fade out/fade in trong pushViewController hoạt hình
- 17. Không có bóng/dập nổi trên UIBarButtonItem
- 18. Cách thay đổi hình ảnh và vô hiệu hóa UIBarButtonItem
- 19. Làm cách nào để khôi phục chức năng nút quay lại trong UINavigationController?
- 20. Cách thay đổi kích thước hình ảnh UIBarButtonItem
- 21. Ẩn UIToolbar của UINavigationController trong khi xemWillDisappear:
- 22. Lập trình thay đổi thuộc tính định danh của UIBarButtonItem
- 23. Tiêu đề UINavigationController không được hiển thị?
- 24. Thay đổi phông chữ của tiêu đề UINavigationController
- 25. Thay đổi giao diện của thanh công cụ từ UINavigationController
- 26. Có thể bật UINavigationController hai lần không?
- 27. UINavigationController có khoảng cách thanh trạng thái thêm ở đầu
- 28. Thêm UIBarButtonItem vào navigationItem.titleView?
- 29. UIBarButtonItem có màu?
- 30. UIBarButtonItem Tuỳ chỉnh xem trong UINavigationBar