0

モーダルビューコントローラーをプッシュしているアプリがあります。正常に動作していますが、最も正しい方法でコーディングしていないことが懸念されます。私は 2 つのナビゲーション コントローラーをインスタンス化しましたが、これは少し危険に思えます。

基本的に、3 つのタブを持つタブ バー コントローラーを作成し、それらのタブ/ビュー コントローラーの 1 つをルートにしました。後で、ユーザーが段落内の特定の単語に触れると、(コア テキストに独自のマークアップを使用して) ビュー コントローラーをポップします。プッシュされたView Controllerには、正常に機能する戻るボタンがあり、アプリは問題ないようです。

私が言ったように、それはすべてうまくいきますが、私はここでサークルでコーディングしているようです. これは正しいです?

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];
}
4

1 に答える 1

0

答えは「はい」のようです。アプリには単一のナビゲーション コントローラーがあるという印象を受けましたが、そのタブからさらにプッシュされるかどうかに応じて、タブごとに 1 つのようなものです。

于 2012-07-08T20:47:49.480 に答える