Share Coding

Tutorials, Problems, Stuffs …

Objective C – Basic UIView with navigation controller

This is a changing views solution:

[self presentModalViewController:view animated:YES];

 

In some situations that wanting to use Navigation Controller’s changing page animation effect:

AppDelegate.m

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
	// IOS 5.x
	self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
	self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
	UINavigationController *nvc =[[UINavigationController alloc] initWithRootViewController:viewController];
	nvc.navigationBar.barStyle = UIBarStyleBlack;
	[window addSubview:nvc.view];
	[self.window makeKeyAndVisible];
	return YES;

	/* IOS 4.x
	UINavigationController *nvc =[[UINavigationController alloc] initWithRootViewController:viewController];
	nvc.navigationBar.barStyle = UIBarStyleBlack;
	[window addSubview:nvc.view];
	[self.window makeKeyAndVisible];
	return YES;
	*/
}

 
ViewController.m

-(void) viewDidLoad {
	[super viewDidLoad];
	// Customize the bar on different view
	self.navigationController.navigationBarHidden = true;
}

 
We can change the currentView by navigationController like this:

-(void) buttonPressed {
	nextPage *nextPage = [[nextPage alloc] init];
	[self.navigationController pushViewController:nextPage animated:YES];
}
Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: