zerowords
zerowords

Reputation: 3113

view did load but not viewDidLoad

I have two view controllers: BSViewController and BSotherViewController. BSViewController has a button on it that is segues to BSotherViewController. That part works fine and I can see the one VC and then the "other" VC when I run on the simulator. But I have an NSLog(@"other"); in BSotherViewController's -viewDidLoad which is not showing in the console. A similar NSLog(@"other"); in BSViewController's -viewDidLoad which is showing in the console. I suspect the problem is the lack of an IBAction but I cannot figure where it should go and how it should be linked in the storyboard.

BSViewController.h

#import <UIKit/UIKit.h>

@interface BSViewController : UIViewController

@property (nonatomic) NSInteger number;
@end

BSViewController.m

#import "BSViewController.h"

@interface BSViewController ()
@end
@implementation BSViewController
@synthesize number;

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    self.number = 25;
    NSLog(@"number: %d", self.number);
}

@end

BSotherViewController.h

#import <UIKit/UIKit.h>

@interface BSotherViewController : UIViewController
@property (nonatomic) NSInteger anumber;
@end

BSotherViewController.m

#import "BSotherViewController.h"
#include "BSViewController.h"
@interface BSotherViewController ()

@end

@implementation BSotherViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    NSLog(@"other number:");
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    BSViewController *view = [[BSViewController alloc] init];
    self.anumber = view.number;
    NSLog(@"other number: %d", self.anumber);
}

storyboard

Upvotes: 1

Views: 1183

Answers (1)

Mr Rogers
Mr Rogers

Reputation: 6251

In the storyboard is the second view controller set up as a BSotherViewController? You can verify by hovering over the view controller icon in the storyboard.

hovering

If it's not, then click it and go to the identity controller and type it in.

identity

Upvotes: 1

Related Questions