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;
@endindependentCoverViewController.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?!