Pergunta

I have a button that I have added to my navigation bar programatically. When I pressed this button, sometimes I want it to [self.navigationBar popViewControlleranimated:YES] and sometimes I want it [self.navigationBar pushViewcontrollerAnimated:YES] depending on some variables. I can get the popViewController part to work, but I am unsure how to do the pushViewController part. Mainly, where do I instantiate this viewController? As I understand it, it has to be part of the navigation controller already. But if I made this view in my story board, what do I connect it to to make it part of the navigation controller since my button is inserted programatically? Also, even if my button was not inserted programatically, and I instead added it via the story board, how would the case work when I want to popViewController upon pressing the button? If I link the pushViewController to this button, woudln't it try to push this view controller when I actually want to pop it? I suppose I could do and unanimated pop followed by an animated one, which might work.

Foi útil?

Solução

Simply connect the two nibs in your storyboard with a push segue( from the class of the one to the whole other): enter image description here and set it's identifier "something" enter image description here , then in your code replace push view controller with:

[self performSegueWithIdentifier:@"something" sender:self];
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top