0

I have a working application which I am just trying to enhance. It's a simple Table View controller which has a plus button; the user clicks that and is modally presented with an Add Entry View Controller which contains a UIDatePicker and 4 text fields.

Right now, the text fields behave normally; you click on them and the keyboard comes up.

I am enhancing my application though to be so that a user taps TextField 1 and is taken modally to a new TableViewController, where they'd essentially be able to Create new entries or select existing ones.

If the user clicks textField 2, they'd go modally to the Table View Controller for that text field (which is different to the first Table View).

How would I go about doing this?

Right now, I have added in a modal segue in the story board for the first text field and when clicking that text field in the running application, the keyboard appears. However, as soon as I dismiss the keyboard, the new table view controller gets modally presented. I want to eliminate the keyboard appearing and show just the table view modally.

Attempting the code below meant I could not modally go to any table view or not pull up the keyboard for any text field because it's not distinguishing between text fields.

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
    return NO; 
}

Any assistance on differentiating between the text fields to call modally different table views would be really helpful.

Thanks

amitsbajaj
  • 1,304
  • 1
  • 24
  • 59

2 Answers2

0

What i understand is, need to present(push) the UIViewControllers(TableViews) on already the presented(modally) viewController, If so

First you have to present your modal view controller inside a navigation controller:

    EmailIDValidationController *obj  = [self.storyboard instantiateViewControllerWithIdentifier:@"EmailIDValidataion"];

    UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:obj];
    [self presentViewController:nc animated:YES completion:Nil];

Then inside the presented VIewController, you can do this:

  presentedViewController *obj  = [self.storyboard instantiateViewControllerWithIdentifier:@"STORYBARDID"];
  [self.navigationController pushViewController:obj animated:YES];

You need to get the tableViewControllers by the UITextField events. So Use the delegates of it;

 -(void)textFieldDidBeginEditing:(UITextField *)textField{
    presentedViewController *obj  = [self.storyboard instantiateViewControllerWithIdentifier:@"STORYBARDID"];
    [self.navigationController pushViewController:obj animated:YES];
}
Kumar KL
  • 15,315
  • 9
  • 38
  • 60
  • Dear Kumar - thanks for the reply. That's basically it but I'm not understanding a few things. I'm new to iOS programming and am working entirely with iOS 7 and storyboards. From the textFieldShouldBegin, I need to present a Table View Controller Modally. I'm not using NibNames or anything like that here.. but when I try to type that code out [self presentModal..., it shows depreciated in iOS 6. I basically want the ability to click on TextFied 1 (tag == 100) and present a Table View Controller Modally.. any thoughts? Sorry for the basic questions! – amitsbajaj Mar 03 '14 at 12:48
  • Check this to get the StoryBoard ID **http://stackoverflow.com/questions/16351348/example-for-login-screen-modally-based-on-storyboard/16351631#16351631** – Kumar KL Mar 03 '14 at 12:55
  • Hi Kumar - thanks for the information but I'm sorry, I just don't get it.. can we set up a chat to discuss it please? – amitsbajaj Mar 03 '14 at 13:14
  • @Lavanya Sorry. I was offline. so what's the exact problem? – Kumar KL Mar 04 '14 at 04:19
0

A simple fix.

Creating the segue in the Storyboard (as Modal) and applying textFieldDidBeginEditing instead of shouldBegin, I was able to set the tag and hide the keyboard. This did the trick by calling the new VC.

amitsbajaj
  • 1,304
  • 1
  • 24
  • 59