osx - Navigation between NSVIewController -
i new mac osx app development. in application have 3 nsviewcontrollers, practicecontroller, notecontroller , questioncontroller. have navigate noteviewcontroller practicecontroller , questioncontroller , comeback viewcontroller notecontroller has navigated.
for example: when navigate notecontroller practicecontroller, when tap on button notecontroller have come practicecontroller, , when navigate notecontroller questioncontroller, when tap on button notecontroller have come questioncontroller.
please me how this? badly searching it. thanks.
well, after long time search, found open source library ports uikit macosx.
https://github.com/bigzaphod/chameleon.git
it's complicated me, wrote own navigation controller.
nsnavigationcontroller.h
#import <cocoa/cocoa.h> @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
nsnavigationcontroller.m
#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
baseviewcontroller.h
#import <cocoa/cocoa.h> @class nsnavigationcontroller; @interface baseviewcontroller : nsviewcontroller @property (nonatomic, weak) nsnavigationcontroller *navigationcontroller; @end
baseviewcontroller.m
#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
it's simplest navigationcontroller. didn't implement view animation. hope can help.
Comments
Post a Comment