4

このチュートリアルを読み、iPhone用のフォトギャラリーを作成しました。次に、それをTabBarプロジェクトに追加します。Three20はXIBをサポートしていないと聞いたので、タブバーの設定全体をプログラムで変更しました。私は最終的な解決策からそれほど遠くないと思います。

フォトギャラリーを1つのタブで機能させることができましたが、機能はありません(写真をクリック->開くなど)。詳細画像ページに移動するページ上部のナビゲーションはありません。これをdidFinishLaunchingWithOptionsから削除したときに直面しました-アプリデリゲートのメソッド:

// Override point for customization after application launch
TTNavigator* navigator = [TTNavigator navigator];
TTURLMap* map = navigator.URLMap;
[map from:@"demo://album" toViewController:  [AlbumController class]];

[navigator openURLAction:[TTURLAction actionWithURLPath:@"demo://album"]];
return YES;

タブバー全体が表示されないため、削除する必要がありました。フォトギャラリーは画面全体を使用します。表示されていないのか、ロードされていないのかわかりません。私も試しました:

tabbar.hidesBottomBarWhenPushed = NO;

しかし、それはまったく機能しませんでした。TTNavigatorコードをAlbumController自体のloadView()、viewDidLoad()、init()に追加しようとしましたが、結果はありませんでした。それを機能させるために私がこれをどこに置かなければならないか誰かが知っていますか?

私のAlbumController.h:

#import <Foundation/Foundation.h>
#import <Three20/Three20.h>

@interface AlbumController : TTThumbsViewController {
    // images
    NSMutableArray *images;

    // parser
    NSXMLParser * rssParser;
    NSMutableArray * stories;
    NSMutableDictionary * item;
    NSString * currentElement;
    NSMutableString * currentImage;
    NSMutableString * currentCaption;
}

@property (nonatomic, retain) NSMutableArray *images;

@end

そして、didFinishLaunchingWithOptions-methodの私の実装:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    

    // set up tab bar controller
    tabBarController = [[UITabBarController alloc] init];        
    albumController = [[AlbumController alloc] init];  
    firstViewController = [[FirstViewController alloc] init];  
    secondViewController = [[SecondViewController alloc] init];  
    firstViewController.delegateRef = self;
    tabBarController.viewControllers = [NSArray arrayWithObjects:firstViewController, secondViewController, albumController, nil];  
    [window addSubview:tabBarController.view];                                             
    [window makeKeyAndVisible]; 

    // Override point for customization after application launch
    TTNavigator* navigator = [TTNavigator navigator];
    TTURLMap* map = navigator.URLMap;
    [map from:@"demo://album" toViewController:  [AlbumController class]];
    [navigator openURLAction:[TTURLAction actionWithURLPath:@"demo://album"]];
    return YES;
}

ありがとうみんな、乾杯、ドゥーノット

4

3 に答える 3

6

ブライアンの助けを借りて、タブ バー アプリケーションでフォト ギャラリーを実行することができました。この解決策を探している人が非常に多いので、できる限り説明するようにしています。

Three20 を Interface Builder で使用することはできないようです。そのため、タブ バー アプリケーションを手動でセットアップする必要があります。これは私の Three20PhotoGalleryAppDelegate.h です:

#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 とすべての ViewController を必ず作成してください。私の 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

上記の問題の説明で説明したように、私のフォト ギャラリーは常にフル スクリーンを使用していました。タブバーのアイコンを使用できなくなるため、これは悪いことです。このためには、追加する必要があります

self.hidesBottomBarWhenPushed=NO;

上記の AlbumController-init-method で述べたように、あなたの init() メソッドに。

すっごく、それだけです。誰かが私のソリューションを再利用できることを本当に願っています。ブライアンに再び感謝します。

乾杯、ドゥーノット

PS: github でプロジェクトを作成しました。サンプルアプリはこちらからダウンロードできます。

于 2011-01-14T18:13:00.433 に答える
0

これを試して:

tBarController = [[UITabBarController alloc] init];
 actionController = [[ActionController alloc] initWithNibName:nil bundle:nil];
    // Override point for customization after application launch.
    TTNavigator* navigator = [TTNavigator navigator];
 TTURLMap* map = navigator.URLMap;
 [map from:@"demo://album" toViewController:tBarController];
 [tBarController setViewControllers:
     [NSArray arrayWithObjects:actionController,nil]];
 [navigator openURLAction:[TTURLAction actionWithURLPath:@"demo://album"]];

 [self.window addSubview:tBarController.view];
 [self.window makeKeyAndVisible];

    return YES;
于 2011-01-13T03:28:02.863 に答える
0

TTNavigatorDemo サンプルを使用して、タブ バー コントローラーでの使用方法を学習できます。

于 2011-02-03T20:26:06.433 に答える