자, Bryan의 도움으로 나는 탭 갤러리 애플리케이션에서 사진 갤러리를 실행할 수있었습니다. 나는이 솔루션을 찾고있는 많은 사람들을 보았으므로 가능한 한 그것을 설명하려고 노력했다.
인터페이스 빌더와 함께 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, 그게 전부입니다. 누군가가 내 솔루션을 다시 사용할 수 있기를 바랍니다. Bryan에게 다시 한 번 감사드립니다.
건배들, PS
doonot : 나는 GitHub의에서 프로젝트를 만들었습니다. 샘플 앱
here을 다운로드 할 수 있습니다.
dooonot, 사진 갤러리 + tabbar의 샘플 코드가 있습니까? –
https://github.com/doonot/TTThumbsViewController-in-a-TabBar-App – doonot