Como chamar uma nova viewController através do clique de um botão dinâmico>

Joined
Feb 1, 2012
Messages
3
Reaction score
0
Points
1
A minha dúvida é a seguinte:

Eu possuo uma scrollView anode eu crio botões programaticamente e neles adiciono imagens. Estes botões tem a aparência de imagens criadas aleatoriamente.

Para saber em qual botão eu cliquei, eu utilizo:

######################################

for (int i=1; i<7; i++)
{
UIButton *botao = [[UIButton buttonWithType:UIButtonTypeCustom] retain];
botao.frame = CGRectMake((i-1)*199, 0, 199, 169);
botao.backgroundColor = [UIColor whiteColor];
[botao setBackgroundImage:[UIImage imageNamed:[NSString stringWithFormat:mad:"imagem%d.jpg", i]] forState:UIControlStateNormal];

botao.tag = i;

[botao addTarget:self action:mad:selector(chamaProximaViewController:) forControlEvents:UIControlEventTouchUpInside];

[botao release];
}

######################################


Então eu chamo uma função pelo clique do botão:

[botao addTarget:self action:mad:selector(chamaProximaViewController:) forControlEvents:UIControlEventTouchUpInside];


E então esta função tem o objetivo de identificar o clique e chamar outra view Controller:

######################################

#import "ProximaViewController.h"

-(IBAction)chamaProximaViewController:(id)sender
{
UIButton *clicado = (UIButton *) sender;
NSLog(@"Clicou no nº %d",clicado.tag);

ProximaViewController *proximaViewController = [[ProximaViewController alloc] init];
proximaViewController.propriedadeTipoInt = clicado.tag; //1,2,3,4…
[proximaViewController setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
[self presentModalViewController:proximaViewController animated:YES];
}

######################################

O problema é que quando eu executo a aplicação e clico no botão respectivo, a próxima view é importada, ocorre o flip horizontal, e aparentemente a view é chamada. Porém a tela FICA ESCURA. Como se nenhum dos objetos da tela estivessem aparecendo. Como se TUDO TIVESSE SUMIDO.

Coloquei alguns NSLogs na "proximaViewController" para saber se a "ProximaViewController" está sendo chamada. E está! Funciona! O problema é que tudo é carregado, mas nenhum objeto da tela é mostrado.

OBS: Eu possuo outras chamadas para a "proximaViewController" que funcionam através de "Segues". Mas neste caso, como os botões são criados dinamicamente, eu não posso criar "Segues" para isso.

Como eu faço então, para fazer com que os objetos da "proximaViewController" não sumam quando eu carregar a "proximaViewController" pela função "chamaProximaViewColler"?
 

vansmith

Senior Member
Joined
Oct 19, 2008
Messages
19,924
Reaction score
559
Points
113
Location
Queensland
Your Mac's Specs
Mini (2014, 2018, 2020), MBA (2020), iPad Pro (2018), iPhone 13 Pro Max, Watch (S6)
La mayoría de la gente de aquí hablan Inglés como su idioma principal. Por lo tanto, si puede, lo mejor sería si se pudiera publicar su pregunta en Inglés.

For the rest of us: "The majority of the people here speak English as their primary language. As such, if you can, it would be best if you could post your question in English."
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top