
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 <UIKit/UIKit.h>
@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.
Todo dia confiro sobre novos posts, e já tava achando que você tinha parado. Valeu!
Por: André Pedroza em 29/06/2009
às 21:39
Muito bom o conteudo dos posts, parabens continue com esse otimo trabalho.
Obrigado
Por: Wesley Alberini em 03/07/2009
às 14:16
Olá Claudio, primeiramente parabéns pelo trabalho que esta fazendo aqui, esta realmente ajudando muita gente pelo que vejo, estou descobrindo esse mundo de desenvolvimento agora, baixei o pacote SDK no meu mac mas realmente para quem nunca teve contato fica dificil, gostaria muito de fazer um curso bem completo para desenvover p/ iphone, você teria alguma sugestão para me dar?
mais uma vez muito obrigada e parabéns!!
Abraços
Por: Taiana em 03/07/2009
às 14:44
Olá Taiana, é difícil não só para quem está começando como também para quem programa em outra linguagem. Bem, como sou do Rio, até agora só vi um curso sobre iPhone mas se você mora em SP tem vários. Vou abrir uma página com os melhores ainda esta semana. Beijos.
Por: webclaudio em 12/07/2009
às 03:04
Muio bom, estou no aguardo dos novos posts, parabens!!
Obrigado
Por: Wesley Alberini em 06/07/2009
às 01:48
Ótimo material, estou te acompanhando, espero por mais.
Obrigado por essa sua iniciativa, ajuda muito!
Por: Bruno Alcântara em 20/07/2009
às 21:22
Claudio,
Qual o procimo topico que vai preparar?
Abs
Por: Wesley Alberini em 23/07/2009
às 02:21
Olá, pretendo iniciar o processo de criação de uma aplicação para iPhone. Meu maior problema é tempo. mas vai sair alguma coisa neste sábado. Abraços.
Por: webclaudio em 24/07/2009
às 01:31
Aew claudio, parabens mesmo ai pelos tuto…
Agora eu tenho umas duvidas…tem como vc refazer a parte do xib, é que quase ela toda ficou num ponto onde num se via o que vc tava fazendo, e tem uma parte lá, que vc fala que é pra clicar com o botao esquerdo no file owners, so que num faz nada, mais se eu clicar com o direito ele abre uma janelinha lá e tal, mais num sei se é a mesma que vc fala ai no projeto, tem como vc refazer só essa parte ou ajeitar o video se possivel, obg.
Uma outra coisa é se invez de na Tela1 eu quizer colocar uma imagem, tem como??Explica ai pra gente por favor…agradeço mesmo.
Abraço cara e ate uma proxima.
Por: Flavio em 21/08/2009
às 12:05
Recentemente comprei um iphone, ai estava eu procurando na net um site sobre programação para iphone qdo derrepente encontrei o webclaudio,fiquei impressionado com a qualidade, capricho e a dedicação que tu tens em dividir o conhecimento, parabens!!!! Acabas de ganhar mais um seguidor!!!!
Por: Marcos em 25/08/2009
às 03:44
parabens pela iniciativa.
Mas repare que nos seus videos estão bem ruins de visualizar! as vezes você ta com o mouse numa parte da tela mas a camera não esta mostrando essa parte.
Nesse você fez isso varias vez, há uma grande dificuldade em visualizar. Ta terrivel!
Por: Deyvit Silva em 11/02/2011
às 13:07