Problems displaying modal representation programmatically

I am very new to iOS / Objective C programming.

The flow of events I want to execute is this: the user selects a tab from the tab view controller of the tab bar. After downloading VIEW A, it will open a modal window to get some information

VIEW A - (void) viewDidLoad

ModalYearPickerViewController *modalYearPickerViewController= [[ModalYearPickerViewController alloc] init]; [self presentViewController:modalYearPickerViewController animated:NO completion:nil]; 

I try to have my order picker load immediately, so the user can select the year from my picker (in VIEW B), and then close the modal window after the value has been returned back to VIEW A.

Now the fist view is loaded, then it automatically switches to the black screen. I am not sure why, since my view controller for modalYearPickerViewController has a collector, etc.

Any advice or help on downloading the software management module would be greatly appreciated!

Thanks!

+4
source share
2 answers

If you are using storyboards:

 UIStoryboard *storyBoard = [self storyboard]; 

This will return the storyboard of the current controller. I assume your view controller A is also on your storyboard.

 ModalYearPickerViewController *modalYearPickerViewController = [storyBoard instantiateViewControllerWithIdentifier:@"ModalYearPickerViewController"]; 

This will create an instance of your view controller from the storyboard. But another thing you need to do is set the view manager storyboard identifier to ModalYearPickerViewController . You can set this right below where you set your custom view controller class in the storyboard.

 [self presentViewController:modalYearPickerViewController animated:NO completion:nil]; 

and done.

+8
source

If you have an xib file for this viewContrioller, it must also be loaded to do this:

 ModalYearPickerViewController *modalYearPickerViewController = [[ModalYearPickerViewController alloc] initWithNibName:@"ModalYearPickerViewController" bundle:nil]; 
0
source

Source: https://habr.com/ru/post/1479411/


All Articles