2
votes

I have written the following class:

.h:

#import <Foundation/Foundation.h>
@class TDLPaneViewController;

@interface TDLSubViewController : NSObject

@property (nonatomic, strong) IBOutlet UIView* view;
@property (nonatomic, strong) TDLPaneViewController* paneViewController;

- (id) initWithNibName:(NSString*)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil;

- (void)viewWillAppear:(BOOL)animated;
- (void)viewDidAppear:(BOOL)animated;
- (void)viewWillDisppear:(BOOL)animated;
- (void)viewDidDisppear:(BOOL)animated;

@end

.m:

#import "TDLSubViewController.h"

@interface TDLSubViewController ()
{
     UIView *view;
}

@property (nonatomic, strong) NSString* nibName;
@property (nonatomic, strong) NSBundle* nibBundle;

@end

@implementation TDLSubViewController

@synthesize paneViewController, view;
@synthesize nibName, nibBundle;

- (id)initWithNibName:(NSString*)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super init];

    if (self)
    {
          self.nibName = nibNameOrNil;
          self.nibBundle = nibBundleOrNil;
    }
}

- (void)viewWillAppear:(BOOL)animated
{
     NSLog(@"viewWillAppear:%i", animated);
}
- (void)viewDidAppear:(BOOL)animated
{
     NSLog(@"viewDidAppear:%i", animated);
}
- (void)viewWillDisppear:(BOOL)animated
{
     NSLog(@"viewWillDisppear:%i", animated);
} 
- (void)viewDidDisppear:(BOOL)animated
{
     NSLog(@"viewDidDisppear:%i", animated);
}

@end

I get error when showing another view: - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated];

     TDLTestSubViewController* subView = [[TDLTestSubViewController alloc] initWithNibName:@"TDLTestSubViewController" bundle:nil] ;

     [self pushSubViewController:nil animated:YES leftSide:YES];

} 

TDLTestSubViewController is child class of TDLSubViewController.

If I use UIViewController instead of TDLTestSubViewController everything works fine and if I turn ARC off it's OK too. So I think the problem is in the TDLSubViewController class. Please, suggest what could be wrong?

1
why aren't you returning self from initWithNibName() ?giorashc

1 Answers

5
votes

Your initWithNibName:bundle: method doesn't return self when it must.