Bryanの助けを借りて、私は写真ギャラリーをタブバーアプリケーションで稼働させることができました。私はこのソリューションを探している多くの人々を見てきましたので、私はそれを私ができるほど良いものとして説明しようとしています。
Interface BuilderでThree20を使用することはできないようですので、タブバーアプリケーションを手動で設定する必要があります。
#import <UIKit/UIKit.h>
#import <CoreData/CoreData.h>
#import "AlbumController.h"
#import "SecondViewController.h"
#import "FirstViewController.h"
@class TabBarAppViewController;
@class AlbumController;
@class SecondViewController;
@class FirstViewController;
@interface Three20PhotoGalleryAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
UITabBarController *tabBarController;
AlbumController *albumController;
FirstViewController *firstViewController;
SecondViewController *secondViewController;
@private
NSManagedObjectContext *managedObjectContext_;
NSManagedObjectModel *managedObjectModel_;
NSPersistentStoreCoordinator *persistentStoreCoordinator_;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) UITabBarController *tabBarController;
@property (nonatomic, retain) AlbumController *albumController;
@property (nonatomic, retain) SecondViewController *secondViewController;
@property (nonatomic, retain) FirstViewController *firstViewController;
@property (nonatomic, retain, readonly) NSManagedObjectContext *managedObjectContext;
@property (nonatomic, retain, readonly) NSManagedObjectModel *managedObjectModel;
@property (nonatomic, retain, readonly) NSPersistentStoreCoordinator *persistentStoreCoordinator;
- (NSURL *)applicationDocumentsDirectory;
- (void)saveContext;
@end
は、新しいUITabBarControllerだけでなく、すべてのあなたのViewControllersを作成することを確認してください:これは私のThree20PhotoGalleryAppDelegate.hです。のは、私のThree20PhotoGalleryAppDelegate.mを続けてみましょう:
#import "Three20PhotoGalleryAppDelegate.h"
#import "AlbumController.h"
#import "SecondViewController.h"
#import "FirstViewController.h"
#import <Three20/Three20.h>
@implementation Three20PhotoGalleryAppDelegate
@synthesize window;
@synthesize albumController;
@synthesize firstViewController;
@synthesize secondViewController;
@synthesize tabBarController;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// set up tab bar controller manually
tabBarController = [[UITabBarController alloc] init];
albumController = [[AlbumController alloc] init];
firstViewController = [[FirstViewController alloc] init];
secondViewController = [[SecondViewController alloc] init];
/* This is the essential part of the solution. You have to add the albumController to a
new navigation controller and init it as RootViewController*/
UINavigationController* navController = [[[UINavigationController alloc] initWithRootViewController:albumController] autorelease];
// now add all controllers to the tabBarController
tabBarController.viewControllers = [NSArray arrayWithObjects:firstViewController, secondViewController, navController, nil];
[window addSubview:tabBarController.view];
[window makeKeyAndVisible];
}
- (BOOL)application:(UIApplication*)application handleOpenURL:(NSURL*)URL {
TTOpenURL([URL absoluteString]);
return YES;
}
- (void)dealloc {
[tabBarController release];
[window release];
[super dealloc];
}
@end
はチュートリアルからTTNavigatorのものを必要としないことに注意してください。今私たちはフォトギャラリーをどうやって取得しなければなりません。チュートリアルのようにAlbumControllerでビルドしました。これは私のAlbumController.hです:
#import <Foundation/Foundation.h>
#import <Three20/Three20.h>
@interface AlbumController : TTThumbsViewController {
}
@property (nonatomic, retain) NSMutableArray *images;
@end
上記のチュートリアルでは、AlbumControllerの実装を見つけることができます。今度はAlbumController.m:
#import "AlbumController.h"
#import "PhotoSource.h"
#import "Photo.h"
@implementation AlbumController
@synthesize images;
- (id)init
{
if (self = [super init])
{
// Initialization code
self.title = @"Photo Gallery";
self.hidesBottomBarWhenPushed=NO;
}
return self;
}
- (void)viewDidLoad {
[self createPhotos]; // method to set up the photos array
self.photoSource = [[PhotoSource alloc]
initWithType:PhotoSourceNormal
title:@"All in Vain"
photos:images
photos2:nil];
}
-(void)createPhotos {
// your independent implementation
}
@end
上記の問題の説明にあるように、私のフォトギャラリーは常にフルスクリーンを使用していました。もうタブバーアイコンを使用できないため、これは悪いことです。このためには、上記のAlbumController-init-methodで説明したように、init()メソッドに
self.hidesBottomBarWhenPushed=NO;
を追加する必要があります。
Sooo、それはかなりです。誰かが自分のソリューションを再利用できることを本当に願っています。ブライアンにもう一度感謝します。
乾杯のみんな、 doonot
PS:私はgithubの上のプロジェクトを作成しました。サンプルアプリケーションhereをダウンロードできます。
dooonot、フォトギャラリー+タブバーのサンプルコードがありますか? –
https://github.com/doonot/TTThumbsViewController-in-a-TabBar-App – doonot