私の最初の iPhone アプリには、NavigationController があります。AppDelegate で UINavigationController のインスタンスを定義し、それを既定のナビゲーション コントローラーに設定するにはどうすればよいですか?
.h:
@interface DefaultTableAppDelegate : NSObject <UIApplicationDelegate, UITabBarControllerDelegate>
{
//...
UINavigationController *myNavigationController;
}
@property (strong, nonatomic) UIWindow *window;
@property (nonatomic, strong) UINavigationController *myNavigationController;
//...
@end
.m:
#import "DefaultTableAppDelegate.h"
#import "SHKConfiguration.h"
#import "SKCustomConfigurator.h"
#import "DefaultTableViewController.h"
@implementation DefaultTableAppDelegate
@synthesize window = _window;
@synthesize myNavigationController = _myNavigationController;
//...
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//...
DefaultTableViewController *main = [[DefaultTableViewController alloc]init];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
myNavigationController = [[UINavigationController alloc]initWithRootViewController:main];
myNavigationController.navigationBar.hidden = YES;
[self.window addSubview:myNavigationController.view];
self.window.rootViewController=myNavigationController;
[self.window makeKeyAndVisible];
return YES;
}
UINavigationItem の CustomNavigationItem サブクラス:
.h:
#import <UIKit/UIKit.h>
#import "DefaultTableAppDelegate.h"
@interface CustomNavigationItem : UINavigationItem
{
//...
DefaultTableAppDelegate *myDelegate;
}
@end
.m:
#import "CustomNavigationItem.h"
#import "DefaultTableViewController.h"
@implementation CustomNavigationItem
//...
-(IBAction)actionApply:(id)sender
{
myDelegate = [[UIApplication sharedApplication] delegate];
//...
[myDelegate.myNavigationController popViewControllerAnimated:YES];
}
@end
これが私のストーリーボードのスクリーンショットです: http://postimage.org/image/sv6elwmcz/
TabBarController の NavigationItem のクラスは CustomNavigationItem に設定され、NavigationItem の右ボタンには -(IBAction)actionApply:(id)sender アクションがあります。