This is the very simple ToolBar application.In this application we will see how to tool bar add in the application. So let see how it will worked. My last post you can find out from here.
Step 1: Open the Xcode, Create a new project using Navigation Base application. Give the application “ToolBar”.
Step 2: Xcode automatically creates the directory structure and adds essential frameworks to it. You can explore the directory structure to check out the content of the directory.
Step 3: We need to add one UIViewController subclass in the project. Select project -> New file -> select UIViewController subclass . Give the file name “NextViewController”. Create the NextViewController.xib file also.
Step 4: Open the ToolBarViewController.m file and make the following changes:
#import "NextViewController.h"
@implementation RootViewController
– (void)viewDidLoad
{
[super viewDidLoad];
self.navigationItem.rightBarButtonItem = self.editButtonItem;
self.title = @"ToolBar Application";
}
– (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
}
– (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
}
– (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
}
– (void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
}
/*
// Override to allow orientations other than the default portrait orientation.
– (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations.
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/
// Customize the number of sections in the table view.
– (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 5;
}
– (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 1;
}
// Customize the appearance of table view cells.
– (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
// Configure the cell.
cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
cell.textLabel.text = @"Hello World!!!";
return cell;
}
– (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NextViewController *nextViewController = [[NextViewController alloc] initWithNibName:@"NextViewController" bundle:nil];
// …
// Pass the selected object to the new view controller.
[self.navigationController pushViewController:nextViewController animated:YES];
[nextViewController release];
}
– (void)didReceiveMemoryWarning
{
// Releases the view if it doesn’t have a superview.
[super didReceiveMemoryWarning];
// Relinquish ownership any cached data, images, etc that aren’t in use.
}
– (void)viewDidUnload
{
[super viewDidUnload];
// Relinquish ownership of anything that can be recreated in viewDidLoad or on demand.
// For example: self.myOutlet = nil;
}
– (void)dealloc
{
[super dealloc];
}
@end
Step 5: Double click the NextViewController.xib file and open it to the Interface Builder. First select the view window and bring up Attribute Inspector and change the background color. Select Label from the library and place into the view, select the label from view and bring up Attribute Inspector change the Text into “Hello world!!!” , and change font size. Now save the .xib file close it and go back to the Xcode.
Step 6: Compile and run the application in the Simulator.
You can Download SourceCode from here ToolBar