2010-10-30 4 views
1

Qu'est-ce que je fais mal ici?Ajout d'une sous-classe UIView avec xib à UIViewController

Créé:

CustomTab.h

#import <UIKit/UIKit.h> 

@interface CustomTab : UIView { 
IBOutlet UIView *view; 
} 

@property (nonatomic, retain) IBOutlet UIView *view; 

@end 

CustomTab.m

#import "CustomTab.h" 
@implementation CustomTab  
@synthesize view; 

- (id)initWithFrame:(CGRect)frame { 
    if ((self = [super initWithFrame:frame])) { 
     // Initialization code 
    } 
    return self; 
} 

- (void)dealloc { 
    [super dealloc]; 
} 
@end 
  • fichier XIB défini son propriétaire de fichiers à la classe de CustomTab, accroché la vue

Dans ma classe UIViewController

- (void)viewDidLoad { 

    [super viewDidLoad]; 

    CGRect frame = CGRectMake(0, 0, 320, 40); // Replacing with your dimensions 
    CustomTab *myObj = [[CustomTab alloc] initWithFrame:frame]; 

    [self.view addSubview:myObj.view]; 
    [myObj release]; 
} 

Le doesnt sous-vue apparaissent sur l'écran. Qu'est-ce que je rate?

+0

Que comptez-vous apparaître dans IB? – kovpas

+0

comment détectez-vous cette vue n'a pas apparaître, donner des couleurs différentes à la vue et vérifier – Warrior

+0

Que voulez-vous dire? Je m'attends à voir mon UIView personnalisé sur ma sous-classe UIViewController lorsque l'application charge – barfoon

Répondre

2

Le fichier nib ne se lie pas automatiquement à votre UIView. Si votre vue est propriétaire, je suppose que vous pouvez utiliser l'interface loadNibNamed:owner: de NSBundle pour charger votre vue après avoir init init votre vue.

Questions connexes