Can't display modal UIViewController

My app uses one storyboard. I've got a UITableView in the MasterViewController which is embedded in a UINavigation Controller. So, the main interface is a table of items in MasterViewController. I'm using Auto-Layout and Size Classes.


I've added a new ViewController, and setup some UILabels and UIImageViews. I've set the custom class to IndependentCoverViewController (a UIViewController class), and given it a Storyboard ID of "independentCoverView".


In MasterViewController.m I've added a UITapGestureRecognizer on a UIImageView setup in the tableview's viewForHeaderInSection: method. (I can't add the UIImageView to the storyboard, as it's contained in the tableview's header, so is not accessible in the storyboard editor (InterfaceBuilder).)


When the user taps this image, the new IndependentCoverViewController should be displayed as a modal view sliding up from the bottom of the screen. I just cannot get this to work. Just as an FYI, I used to use a segue in iOS 8, but this stopped working in iOS 9 so I enabled Size Classes, and changed it to an adaptive "present modally" segue. It doesn't work. I can trigger the segue, and NSLog that I'm in the prepareForSegue method, but it does the same as below...


When the user taps the image, the showCover selector is executed. I know this works because a quick NSLog does confirm we're now in the showCover method.


showCover is basically this:

- (void)showCover
{
NSLog(@"showCover");
IndependentCoverViewController *upcoming = [self.storyboard instantiateViewControllerWithIdentifier:@"independentCoverView"];
  upcoming.category = @"";
  upcoming.date = coverDate;
  upcoming.dateString = @"";
  upcoming.eventName = coverEventName;
  upcoming.fontName = coverFontName;
  upcoming.imagePath = coverImage;
  upcoming.location = coverLocation;
  upcoming.notes = @"";
  upcoming.showWeather = coverShowWeather;
  [self goIntoTheBackground];  // This just disables an NSTimer that's being used in MasterViewController
  [self presentViewController:upcoming animated:YES completion:nil];


I've tried [self presentViewController:animated:completion:], and I've tried [self.navigationController pushViewController:animated:], but neither method will actually display the IndependentCoverViewController.


I've added an NSLog to the viewDidLoad method of the IndependentCoverViewController but it is never reached.


If I override loadView, and pop an NSLog in there, it will be called, but that's not really the point. The view controller is already setup in the storyboard, I shouldn't have to override the loadView method.


Here are the various files:

IndependentCoverViewController.h:

#import <UIKit/UIKit.h>

@interface IndependentCoverViewController : UIViewController

@property (nonatomic, copy) NSString *category;
@property (nonatomic, copy) NSDate *date;
@property (nonatomic, copy) NSString *dateString;
@property (nonatomic, copy) NSString *eventName;
@property (nonatomic, copy) NSString *fontName;
@property (nonatomic, copy) NSString *imagePath;
@property (nonatomic, copy) NSString *location;
@property (nonatomic, copy) NSString *notes;
@property (nonatomic, assign) BOOL showWeather;
@property (weak, nonatomic) IBOutlet UILabel *labelDate;
@property (weak, nonatomic) IBOutlet UIImageView *imageViewCover;
@property (weak, nonatomic) IBOutlet UIImageView *imageViewHideCover;
@property (weak, nonatomic) IBOutlet UIVisualEffectView *visualEffectView;
@property (weak, nonatomic) IBOutlet UIImageView *arrowImageView;
@property (weak, nonatomic) IBOutlet UILabel *labelDays;
@property (weak, nonatomic) IBOutlet UILabel *labelValueDays;
@property (weak, nonatomic) IBOutlet UILabel *labelTime;
@property (weak, nonatomic) IBOutlet UILabel *labelValueTime;
@property (weak, nonatomic) IBOutlet UITextView *textViewNotes;
@property (weak, nonatomic) IBOutlet UIVisualEffectView *imageViewCategoryBackground;
@property (weak, nonatomic) IBOutlet UIImageView *imageViewCategory;
@property (weak, nonatomic) IBOutlet UILabel *labelLocation;
@property (weak, nonatomic) IBOutlet UIVisualEffectView *imageViewWeatherBackground;
@property (weak, nonatomic) IBOutlet UIImageView *imageViewWeatherIcon;
@property (weak, nonatomic) IBOutlet UILabel *labelWeatherDescription;

- (void)closeView:(id)sender;

@end


independentCoverViewController.m:

#import "AppDelegate.h"
#import "Constants.h"
#import "IndependentCoverViewController.h"
#import "UIImage+RoundedCorner.h"

@interface IndependentCoverViewController () <UIGestureRecognizerDelegate>
@end

@implementation IndependentCoverViewController

AppDelegate *theDelegate;
UITapGestureRecognizer *tapRecognizer;

- (void)viewDidLoad
{
  [super viewDidLoad];
  NSLog(@"viewDidLoad");
}


There's obviously other stuff in the implementation, but I don't think it's really relevant to this since we never even see "viewDidLoad" in the console.


When I override loadView and NSLog(@"loadView"), it will display "loadView" in the console, but it'll do it every time the view is accessed. This ends up being 9 times because I've tried to set a variable in that class 9 times (upcoming.category..., upcoming.date... etc.).


What am I doing wrong? Why is it so difficult to display a UIViewController?!

Maybe try explicitly setting the modalPresentationStyle of the presented VC?


I haven't had any such issues but then again I haven't really started using size classes much.

Hi, it's not that. I've figured it out, and it's a bit ridiculous. I've raised it as 23123560, but here's the problem:


- Create a simple app with a storyboard containing two view controllers.

- Add a button on the first one (VC1), and create a "present modally" segue to the second view controller (VC2).

- On VC2, add a UITextView and don't have any default text in it.

- Run the app. Click the button on VC1.

--- VC2 will appear with an empty UITextView, as expected.

- Add the following text to the default text via the storyboard: "1234567890" (without the quotes, obviously).

- Run the app. Click the button on VC1.

--- VC2 appears as expected.

- Change the text in the storyboard to: "123456789".

- Run the app. Click the button on VC1.

--- VC2 will not load or display. This is the problem.


So, when you have default text of fewer than 10 characters (any characters) in a UITextView on a view controller you want to present modally, the VC will not be loaded.

Told you it was ridiculous!

Ah yes. There have been a few threads on that issue. It's a gooder all right. Search for threads about UITextView placeholder on these forums for more hilarity. Hopefully they can get that fixed soon.

Can't display modal UIViewController
 
 
Q