Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Having issues displaying modal view programmatically

I am very very new to iOS programming / Objective C.

The flow of events I want to have happen is: user selects tab from tab bar view controller. Once VIEW A has been loaded 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 am trying to have my year picker view load up right away so the user can select a year from my picker (in VIEW B), then close the modal window after the value has been passed back to VIEW A.

Now, the fist view loads, then goes to a black screen automatically. I am unsure why as my view controller for modalYearPickerViewController has a picker etc on it.

Any tips or help loading a modal view controller programmatically would be greatly appreciated!

Thanks!

like image 644
user2303228 Avatar asked Feb 16 '23 14:02

user2303228


1 Answers

If you are using storyboards :

UIStoryboard *storyBoard = [self storyboard]; 

This will return the storyboard of your current view controller. I am assuming your View Controller A is also on your storyboard.

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

This will instantiate your view controller from the storyboard. But one other thing you have to do is set your view controllers storyboard id 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.

like image 154
Cagdas Altinkaya Avatar answered Mar 03 '23 09:03

Cagdas Altinkaya