I began from a tutorial example that had a UIViewController connected to a nib, but now i’ve decided to do it all programmatically. Consequently, I deleted the nib but without knowing how to implement my controller.
I did something like this:
EventsDetailController *myChild = [[EventsDetailController alloc] init];
[self.navigationController pushViewController:myChild animated:YES];
However, it crashes when I click the specific cell.
Do I have to initWith something? Before when I had a nib it was initWithNib
#import <UIKit/UIKit.h>
@interface EventsDetailController : UIViewController {
NSString *message;
}
@property (nonatomic, copy) NSString *message;
@end
#import "EventsDetailController.h"
@implementation EventsDetailController
@synthesize message;
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
}
-(void)viewDidLoad{
UILabel *theMsg = [[UILabel alloc] initWithFrame:CGRectMake(0,0,200,30)];
theMsg.text = @"hello";
[theMsg release];
[super viewDidLoad];
}
-(void)viewDidUnload{
self.message = nil;
[super viewDidUnload];
}
-(void)dealloc{
[message release];
[super dealloc];
}
@end
Perhaps, I’ll start from scratch, I think it is still looking for the nib I deleted.
I’m assuming that you have the app delegate’s
window.rootViewControllerset to aNavigationControllerinstance, and that instance was created with ainitWithRootViewController, as you mentioned that you’re getting to the point where it crashes when you click on a cell.Looking at the added code, the only thing I see that’s strange is in the ‘veiwDidLoad’ method – you alloc and release ‘theMsg’, but don’t use it. I’m assuming you’ve cut out some code for brevity.
I ended up starting from scratch when I went away from .nib files (about 5 minutes after starting my first iPhone app). I would run with that, adding in your functionality a little at a time.