2012-02-22 10 views
8

UISplitViewについて多くの調査を行い、マスターとディテールに変更のあるビューがある場合にスプリットビューを制御する方法を見つけることができませんでした。UISplitViewControllerがシングルトンでデリゲート

次に、デリゲートであるシングルトンクラスでそれを管理する方法が見つかりました。

私の問題は、それが正しい方法であるかどうかはわかりません。私はreusabilitymemory managmentについて懸念しています。また、私はシングルトンでデリゲートを作るのはAppleのガイドラインだと感じています。

これは私が持っているものである(そして、それは実際に働いている):

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

IMHO、すべてのデザインパターン、アーキテクチャ、それは「問題」を適合する場合「良い」であるあなたが解決しなければならない(とコード組織のためにあなたの個人的な好みに合う)

  • あなたの問題は何ですか?
  • なぜこのオブジェクトが必要ですか?
  • このシングルトンは UIApplicationDelegateとなりますか? :あなたUIApplicationDelegateではなく、サブオブジェクト、私は自分のコードを整理するために、最近使用してきたスキームを作成するよりも、混乱であれば(それシンプル;-)

さらなる議論=>

ください使用カテゴリとクラスの拡張

例:

私のViewControllerクラスはC複雑なタスクを処理する場合odeはグループで分けることができます。
さんが言わせて:

  • コアデータ
  • 位置認識、

が、私はこれらの

  • UIViewController+soundManager
  • UIViewController+dataProviderごとにカテゴリを作成
  • UIViewController+locationManager

(いくつかの@interfaceの@implementationと同じファイル内で、または別のファイルに=>私はいくつかのファイルを使用)

その後、私はプロパティこの特定のカテゴリのニーズのためのクラスの拡張を書き、各カテゴリと一緒に。

0

最後に私はUISplitViewControllerをサブクラス化してこれを解決し、を自分の代理人として使用しました。

関連する問題