
Olá pessoal… Estamos de volta.
E agora aprendendo a fazer nosso primeiro menu usando a tableview. Embaixo do vídeo segue o código para quem não quiser digitar. Um abraço…
CRIANDO UM MENU COM TABLEVIEW
Código rootviewcontroller.h
//
// RootViewController.h
// Menu
//
// Created by Luís Cláudio on 28/06/09.
// Copyright __MyCompanyName__ 2009. All rights reserved.
//
#import
@interface RootViewController : UITableViewController {
NSArray *menu;
}
@end
Código rootviewcontroller.m
//
// RootViewController.m
// Menu
//
// Created by Luís Cláudio on 28/06/09.
// Copyright __MyCompanyName__ 2009. All rights reserved.
//
#import “RootViewController.h”
#import “MenuAppDelegate.h”
#import “Tela1ViewController.h”
@implementation RootViewController
- (void)viewDidLoad {
self.title= @”Meu primeiro Menu”;
menu = [[NSArray alloc] initWithObjects: @”Entrada”, @”Ida para Almoço”,@”Retorno do Almoço”,@”Saída”,nil];
[super viewDidLoad];
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
/*
- (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 YES;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning]; // Releases the view if it doesn’t have a superview
// Release anything that’s not essential, such as cached data
}
#pragma mark Table view methods
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [menu count];
}
// 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] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}
// Set up the cell…
NSInteger row = indexPath.row;
cell.text = [menu objectAtIndex:row];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// Navigation logic may go here. Create and push another view controller.
MenuAppDelegate *delegate = [[UIApplication sharedApplication] delegate];
Tela1ViewController *anotherViewController = [[Tela1ViewController alloc] initWithNibName:@”Tela1″ bundle:nil];
[delegate.navigationController pushViewController:anotherViewController animated:YES];
[anotherViewController release];
}
/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
// Return NO if you do not want the specified item to be editable.
return YES;
}
*/
/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
// Delete the row from the data source
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES];
}
else if (editingStyle == UITableViewCellEditingStyleInsert) {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
}
}
*/
/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/
/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
// Return NO if you do not want the item to be re-orderable.
return YES;
}
*/
- (void)dealloc {
[super dealloc];
}
@end
Abraços e até a próxima aula.
Autor: webclaudio.wordpress.com


15:08
Marcell C. Ribeiro



















0 comentários:
Postar um comentário