Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>well, after a long time search, I found a open source library which ports the UIKit to MacOSX.<br> <a href="https://github.com/BigZaphod/Chameleon.git">https://github.com/BigZaphod/Chameleon.git</a><br> But it's too complicated for me, so I wrote my own Navigation controller.</p> <h3>NSNavigationController.h</h3> <pre><code>#import &lt;Cocoa/Cocoa.h&gt; @class BaseViewController; @interface NSNavigationController : NSResponder @property (nonatomic, strong) BaseViewController *rootViewController; - (id)initWithRootViewController:(BaseViewController *)rootViewController; - (NSView*)view; - (void)pushViewController:(BaseViewController *)viewController animated:(BOOL)animated; - (BaseViewController *)popViewControllerAnimated:(BOOL)animated; @end </code></pre> <h3>NSNavigationController.m</h3> <pre><code>#import "NSNavigationController.h" #import "AppDelegate.h" #import "BaseViewController.h" @interface NSNavigationController () @property (nonatomic, strong) NSMutableArray *viewControllerStack; @end @implementation NSNavigationController - (id)initWithRootViewController:(BaseViewController *)rootViewController { self = [super init]; if (self) { self.rootViewController = rootViewController; self.rootViewController.navigationController = self; self.viewControllerStack = [[NSMutableArray alloc] initWithObjects:self.rootViewController, nil]; } return self; } - (NSView*)view { BaseViewController *topViewController = [self.viewControllerStack objectAtIndex:[self.viewControllerStack count] - 1]; return topViewController.view; } - (void)pushViewController:(BaseViewController *)viewController animated:(BOOL)animated { if (viewController != nil) { [self removeTopView]; [self.viewControllerStack addObject:viewController]; viewController.navigationController = self; [self addTopView]; } } - (BaseViewController *)popViewControllerAnimated:(BOOL)animated { BaseViewController *topViewController = [self.viewControllerStack objectAtIndex:[self.viewControllerStack count] - 1]; [self removeTopView]; [self.viewControllerStack removeLastObject]; [self addTopView]; return topViewController; } - (void)removeTopView { BaseViewController *topViewController = [self.viewControllerStack objectAtIndex:[self.viewControllerStack count] - 1]; [topViewController.view removeFromSuperview]; } - (void)addTopView { BaseViewController *topViewController = [self.viewControllerStack objectAtIndex:[self.viewControllerStack count] - 1]; AppDelegate *delegate = (AppDelegate*)[NSApp delegate]; [delegate.window.contentView addSubview:topViewController.view]; } @end </code></pre> <h3>BaseViewController.h</h3> <pre><code>#import &lt;Cocoa/Cocoa.h&gt; @class NSNavigationController; @interface BaseViewController : NSViewController @property (nonatomic, weak) NSNavigationController *navigationController; @end </code></pre> <h3>BaseViewController.m</h3> <pre><code>#import "BaseViewController.h" @interface BaseViewController () @end @implementation BaseViewController - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Initialization code here. } return self; } @end </code></pre> <p>It's the simplest NavigationController. I didn't implement the view animation. Hope it can help.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload