Ibz
Ibz

Reputation: 518

Notes app for iPhone

In my iPhone application I want to make a page/view where the user can add notes.. essentially write something and then save it... similar to what the Notes app offers on the iPhone... but at a basic level...

I was thinking of something simple like a tableview with a "+" button on the navigation bar that lets the user add a note.

I have googled every possible thing I could think of.. :(

Could someone show me how I would go about implementing this in my view controller?

(I know it seems very simple but I'm new to programming for the iPhone - hence why I'm struggling...)

Upvotes: 2

Views: 2133

Answers (1)

theChrisKent
theChrisKent

Reputation: 15099

You will want to add a barbuttonitem to the navigation bar and set the action to method that launches your Note viewController with a new note. The easiest way to do all that is to use Interface Builder to add the button and hook up the action to a custom method that looks something like this:

- IBAction newButtonPressed:(id)sender
{
    NoteViewController *noteVC = [[NoteViewController alloc] initWithNibName:@"NoteViewController" bundle:nil];     
    [self presentModalViewController:noteVC animated:YES];
    [noteVC release];
}

If you want to add the BarButtonItem from code you can do this in your viewDidLoad method:

UIBarButtonItem *newButton =  [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(newButtonPressed:)];
self.navigationItem.rightBarButtonItem = newButton;
[newButton release];

Note - the above code assumes your View Controller is called NoteViewController and has a Nib called NoteViewController, if you are doing some other form of initialization, then do it there, the important code is the presentModalViewController.

If instead of the modalview approach, you would like a more navigation like entrance (with back button functionality, etc.) you can use the following method instead:

- IBAction newButtonPressed:(id)sender
{
    NoteViewController *noteVC = [[NoteViewController alloc] initWithNibName:@"NoteViewController" bundle:nil];     
    [self.navigationController pushViewController:noteVC animated:YES];
    [noteVC release];
}

Upvotes: 2

Related Questions