2012-02-22 2 views
8

UISplitView에 대해 많은 연구를했으며 마스터와 디테일의 뷰가 변경되면 분할 뷰를 제어 할 수있는 방법을 찾을 수 없었습니다.UISplitViewController가 싱글 톤으로 위임합니다

그런 다음 대리인 인 싱글 톤 클래스로 관리하는 방법을 발견했습니다.

제 문제는 그것이 올바른 방향인지 확신 할 수 없다는 것입니다. 나는 reusabilitymemory managment에 대해 우려하고있다. 또한 싱글 톤으로 대표단을 만드는 것은 애플의 가이드 라인이라고 생각한다.

내가 (그리고 실제로 작동하고) 무엇을 가지고 :

// 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 

이제 구현 :

이 코드는 사용하고있는이 가능한 찾을 것 모두를 위해 자유롭게 변경할 수 있습니다 그들의 프로젝트 :).

모든 비평이 열렬히 환영받을 수 있도록 StackOverflow를 처음 사용했습니다.

답변

2

이럴 모든 디자인 패턴, 아키텍처, 그것은 '문제'를 해결해야 맞는 (코드 조직에 대한 귀하의 개인 환경 설정에 맞는)

  • 문제 무엇인지 '좋은'인가?
  • 왜이 개체가 필요합니까?
  • 이 싱글 톤 UISplitViewDelegate이 (가) UIApplicationDelegate 일 수 있습니까? (단순 ;-)

추가 논의를 유지 =>

당신 UIApplicationDelegate 오히려 하위 개체, 내 코드를 구성 할 최근에 사용했던하는 제도를 만드는 것보다 엉망 일 경우 : 사용 범주와 수준의 확장

예 :

내의 ViewController 클래스는 C 복잡한 작업을 처리하는 경우 ode는 그룹으로 구분할 수 있습니다.
의 말을하자

  • 소리
  • 핵심 데이터
  • 위치 인식,

내가이

  • UIViewController+soundManager
  • UIViewController+dataProvider의 각각에 대한 범주 만들기
  • UIViewController+locationManager.

그런 다음 각 카테고리와 함께 나는 특성이 특정 카테고리의 요구에 맞는 클래스 확장 쓰기 (여러 @interface의 @implementation과 같은 파일 또는 다른 파일에서 => 나는 여러 파일을 사용).

0

지난번에 나는 UISplitViewController을 하위 클래스 화하여 을 자신의 대표자 인으로 사용하여이 문제를 해결했습니다.

관련 문제