Tôi đã nghiên cứu rất nhiều trên UISplitView
và không thể tìm cách điều khiển Chế độ xem Chia tách khi Chế độ xem chính và Chi tiết có chế độ xem thay đổi.Đại biểu UISplitViewController trong một singleton
Sau đó, tôi tìm thấy một cách để quản lý nó với một lớp đơn là đại biểu.
Vấn đề của tôi là tôi không chắc đó có phải là cách đi đúng không. Tôi quan tâm đến số reusability
và memory managment
. Ngoài ra tôi có một cảm giác rằng nó đã làm sáng tỏ các hướng dẫn của Apple để làm cho các đại biểu trong những người độc thân.
Đây là những gì tôi có (và nó thực sự làm việc):
// SharedSplitViewDelegate.h
/* In the detail view controllers:
// in the initial detail view controller
- (void)awakeFromNib
{
[super awakeFromNib];
// needs to be here, otherwise if it's booted in portrait the button is not set
self.splitViewController.delegate = [SharedSplitViewDelegate initSharedSplitViewDelegate];
}
// shared between all detail view controllers
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
SharedSplitViewDelegate *rotationHandler = [SharedSplitViewDelegate initSharedSplitViewDelegate];
[self.toolbar setItems:[rotationHandler processButtonArray:self.toolbar.items] animated:YES];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
*/
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
@interface SharedSplitViewDelegate : NSObject <UISplitViewControllerDelegate>
+ (id)initSharedSplitViewDelegate; // returns the singleton class instance
- (NSArray *)processButtonArray:(NSArray *)array; // Adds and removes the button from the toolbar array. Returns the modified array.
@end
Bây giờ thực hiện:
Mã này là miễn phí để sử dụng và sửa đổi cho tất cả mọi người sẽ tìm thấy nó hữu hiệu trong dự án của họ :).
Tôi mới sử dụng StackOverflow (mặc dù tôi đã ẩn nấp trong một vài tháng mà không có tài khoản) vì vậy mọi phê bình đều được chào đón nồng nhiệt.