【问题标题】:TabBar Support of Three20 iPhone Photo GalleryThree20 iPhone 照片库的 TabBar 支持
【发布时间】:2011-01-11 07:46:38
【问题描述】:

我浏览了this 教程并为 iPhone 创建了一个照片库。现在我想将它添加到我的 TabBar 项目中。我已经听说 Three20 不支持 XIB,所以我将整个标签栏设置更改为编程方式。我认为我离最终解决方案不远了。

我能够让照片库在一个选项卡中工作,但没有功能(单击图片 --> 它打开等)。页面顶部没有导航可引导您进入详细图片页面。当我从应用委托中的 didFinishLaunchingWithOptions-method 中删除它时,我遇到了这个问题:

// 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 方法的实现:

- (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;
}

谢谢大家,干杯,dooonot

【问题讨论】:

    标签: iphone three20 tabbar photo-gallery


    【解决方案1】:

    好的,伙计们,在 Bryan 的帮助下,我能够在标签栏应用程序中运行照片库。我看到很多人都在寻找这个解决方案,所以我尽量解释清楚。

    似乎无法将 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 以及所有的 ViewControllers。让我们继续我的 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;
    

    到你的 init() 方法,就像上面的 AlbumController-init-method 中提到的那样。

    Sooo,差不多就是这样。我真的希望有人可以重新使用我的解决方案。再次感谢 Bryan。

    干杯,伙计们, 不知道

    PS:我在 github 上创建了一个项目。您可以下载示例应用程序here

    【讨论】:

      【解决方案2】:

      试试这个:

      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;
      

      【讨论】:

      • 嗨,布莱恩,非常感谢您的回答。我已经尝试过您的代码,但我只在页面底部看到一个带有黑条的白屏。我试图修改代码,但我无法解决它。还有什么想法吗? :(
      • 我在 Twitter 上收到了你的推文 :)。您说 AlbumController/ActionController 需要是 UITabViewController。我正在使用上述教程中的 AlbumController 代码。本教程使用 TTThumbsViewController,因为我想在照片应用程序中显示这些缩略图。在标签图标下显示“正常”视图完全没有问题......
      • 据我现在所知,我认为 AlbumController 被正确调用,但我认为它隐藏了页面底部的标签栏!我试过 [self.hidesBottomBarWhenPushed=NO];和 [self.wantsFullScreenLayout=NO];但没有成功!
      【解决方案3】:

      您可以使用 TTNavigatorDemo 示例来了解如何将它与标签栏控制器一起使用。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-02-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多