title: How to navigate to the next ViewController programmatically when the a button is pressed?
body: <p>I am new to iPhone apps development. In my code, in first ViewController1 I have a textfield  and a ok- button. So here </p>
  
  <ol>
  <li>When I click ok button without entering a string, it shows an alert message. </li>
  <li>When I enter the string and then press ok button, it should navigate to next ViewController2.</li>
  </ol>
  
  <p>I am able to do the 1st part correctly when I have not connected the ok-button to the ViewController2 in Interface Builder. But when I connect, it navigates and then shows alert message.
  Please tell me how to navigate to ViewController2 programmatically after I enter the string and press ok button.</p>
  
  <p>This is how my code looks for Ok- button:</p>
  
  <pre><code>-(IBAction) okButton: (id) sender
  {
      if([textfield.text isEqualToString:@""])
      {
          UIAlertView *alert= [[UIAlertView alloc] initWithTitle:@"Warning!!" message:@"Enter the file name" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
          [alert show];
      }
      else if(textfield.text!= nil)
      {
          foldername1= [[NSString alloc] initWithString:[NSString stringWithString:textfield.text]];
          NSLog(@"foldername is: %@", foldername1);
      }
      ViewController2 *view2= [[ViewController2 alloc] initWithNibName:@"Next View Name" bundle:nil];
      [self.navigationController pushViewController:view2 animated:YES];
  }
  </code></pre>