I have an iphone app that uses table view as the interface. Each time that the user taps on one of the table cells, I want to show another window to the user. However the user interface of the window that I push into the navigation controller are extremely similar. Therefore I decided to make a “generic nib file” to be used across all the subclasses of the file owner of this generic nib file.
However what I’m confused (and what’s not working) is that I can’t seem to be able to customise this generic nib file. I have this code at the initialisation of the files:
In the .h file:
#import <UIKit/UIKit.h>
#import "primeViewController.h"
@interface subclass1 : primeViewController { //subclassing from a generic view controller that owns a generic nib file
}
In the .m file:
#import "subclass1.h"
@implementation subclass1
- (id) initWithLabelAndButton {
if(self = [super initWithNibName:@"primeViewController" bundle:nil]) {
self.label.text = @"Title of the first subclass";
}
return self;
}
But then when I instantiate the class in the table view:
//somewhere in rootviewcontroller.m:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
switch (indexPath.row) {
case 0:
{
checkPrime* checkPrimeViewController = [[checkPrime alloc] initWithLabelAndButton];
[self.navigationController pushViewController:checkPrimeViewController animated:YES];
[checkPrimeViewController release];
break;
}
default:
break;
}
}
So can anyone tell me what I’m doing wrong? Or am I wrong assuming that xcode allow me to use nib file multiple time across its subclasses? I don’t see why I can’t do it, but I can’t figure out how…
When nib file is loaded, it creates view controller of exactly the same class that is written in .xib (UIViewController, or PrimeViewController, whatever else). What actually is saved in your .nib file?
You’ll succeed if you will store UIView and all the corresponding objects in xib, and will load only them by using [[NSBundle mainBundle] loadNibNamed:@”YourNibFile” owner:class1ViewController options:nil], while view in nib is connected to the corresponding File owner outlet.