使用两个Nav控制器推送View Controller

时间:2012-06-18 17:25:46

标签: ios uinavigationcontroller pushviewcontroller

我有一个应用程序,我正在推动模态视图控制器。它工作正常,但我担心我没有以最正确的方式编码。我已经实现了两个导航控制器,这对我来说似乎有点狡猾。

基本上我已经创建了一个带有3个选项卡的标签栏控制器,然后将其中一个标签/视图控制器设置为根。稍后我(在核心文本上使用一些本地标记)在用户触摸段落中的特定单词时弹出视图控制器。推送的视图控制器有一个后退按钮,工作正常,应用程序似乎没问题。

就像我说这一切都有效,但似乎我在这里编写圈子。这是对的吗?

AppDelegate.h

#import <Foundation/Foundation.h>

@interface AppDelegate : NSObject <UIApplicationDelegate, UITabBarControllerDelegate>
{
    UIWindow *window;
    UITabBarController *tabBarController;
}
@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) UITabBarController *tabBarController;
@end

来自AppDelegate.m

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    ViewController *viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
    ViewController2 *viewController2 = [[ViewController2 alloc] initWithNibName:@"ViewController2" bundle:nil];
    ViewController3 *viewController3 = [[ViewController3 alloc] initWithNibName:@"ViewController3" bundle:nil];

    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:viewController];
    self.tabBarController = [[UITabBarController alloc] init];
    self.tabBarController.viewControllers = [NSArray arrayWithObjects:nav, viewController2, viewController3, nil];
    self.tabBarController.delegate = self;
    self.window.rootViewController = self.tabBarController;
    [self.window makeKeyAndVisible];
    return YES;
}

ViewController3.h

#import <UIKit/UIKit.h>
#import "JSCoreTextView.h"
#import "PopupViewController.h"

@class JSTwitterCoreTextView;

@interface ReadingViewController : UIViewController <JSCoreTextViewDelegate>
{
    JSTwitterCoreTextView *_textView;
    UIScrollView *_scrollView;
}
@end

来自ViewController3.m

这里我实例化了另一个导航控制器。这是个好主意吗?

- (void)textView:(JSCoreTextView *)textView linkTapped:(AHMarkedHyperlink *)link
{
    PopupViewController *popupVC = [[PopupViewController alloc] initWithNibName:@"PopupViewController" bundle:nil];
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:popupVC];
    [nav setModalPresentationStyle:UIModalPresentationFullScreen];
    [nav setModalTransitionStyle:UIModalTransitionStyleCoverVertical];
    [self presentModalViewController:nav animated:YES];
}

来自PopupViewController.m

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self.navigationItem setRightBarButtonItem:[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone 
                 target:self 
                 action:@selector(done:)]];
}

- (void)done:(id)sender
{
    [self.parentViewController dismissModalViewControllerAnimated:YES];
}

1 个答案:

答案 0 :(得分:0)

似乎答案是&#34;是&#34;。我的印象是应用程序有一个单独的导航控制器,但它更像每个标签一个,取决于是否会从该标签进一步推送。