顯示具有 iOS開發 標籤的文章。 顯示所有文章
顯示具有 iOS開發 標籤的文章。 顯示所有文章

2012年7月3日 星期二

使用PresentModalViewController時,來切換下一個 ViewController, 如何還可以使用 navigationController

NextViewController *nextViewController=[[NextViewController alloc]initWithNibName:@"NextViewController" bundle:nil]; UINavigationController *navBar=[[UINavigationController alloc]initWithRootViewController:nextViewController]; [self.navigationController presentModalViewController:navBar animated:YES]; [navBar release]; [nextViewController release]; 參考來源:http://stackoverflow.com/questions/6056726/presentmodalviewcontroller-not-showing-navigation-bar-on-next-view

2012年6月25日 星期一

TabbarController為每個UIView 加上各自的UINavigationController

在TabbarController為每個獨立的 UIView加上各自的UINavigatonController有兩個方法:

一、自已以語法的方式建立。


1、在 ExampleAppDelegate.h 檔加上下面的語法
/*
 *   ExampleAppDelegate.h
 */
@interface ExampleAppDelegate : NSObject 
{
   UIWindow *window;
   UITabBarController *mainBar;
   UINavigationController *firstNav;
   UINavigationController *secondNav;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) UITabBarController *mainBar;
@property (nonatomic, retain) UINavigationController *firstNav;
@property (nonatomic, retain) UINavigationController *secondNav;

@end

2、在 ExampleAppDelegate.m 寫上下面的語法
/*
 *   ExampleAppDelegate.m
 */
#import "ExampleAppDelegate.h"
#import "FirstView.h"
#import "SecondView.h"

@implementation ExampleAppDelegate

@synthesize window;
@synthesize mainBar;
@synthesize firstNav;
@synthesize secondNav;

- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
   firstNav = [[UINavigationController alloc] init];
   FirstView *firstView = [[FirstView alloc] init];
   [firstNav pushViewController:firstView animated:YES];
   firstNav.tabBarItem.title = @"First Tab";
   [firstView release];

   secondNav = [[UINavigationController alloc] init];
   SecondView *secondView = [[SecondView alloc] init];
   [secondNav pushViewController:secondView animated:YES];
   secondNav.tabBarItem.title = @"Second Tab";
   [secondView release];

   mainBar = [[UITabBarController alloc] init];
   mainBar.viewControllers = [NSArray arrayWithObjects:
                                             firstNav, secondNav, nil];

   [self.window addSubview:mainBar.view];
   [self.window makeKeyAndVisible];
   return YES; 
}

- (void)dealloc
{
   [firstView release];
   [secondView release];
   [mainBar release];
   [window release];
   [super dealloc];
}

二、以 xib 的方法建立
可以參考 http://blog.willwinder.com/2011/05/xcode4-uitabbarcontroller-with.html
特要注意的是要在 view 也拉一個 UINavigationControll,然後把UIView 和 UINavigationControll全建立個link 到 ViewController.h檔裡面,然後在 VieDidLoad加上下列的語法:在這邊我把UIView取名為theParentViewOutlet,UINavigationController取名為 navigationController。
這樣的用意是可以取代原本的navigationController。就不用改太多了。
[self.theParentViewOutlet addSubview:self.navigationController.view];
以上的資料參考下面兩個網址:
1、http://ppkko.blogspot.tw/2011/05/tabbarcontroller-navigationcontroller.html

2、http://stackoverflow.com/questions/5163024/uinavigationcontroller-inside-uiview