2011-02-10 113 views
0

我想的Alloc它與一些按鈕的對象類,但無法顯示在父類視圖數據如何分配對象類?

這裏什麼我嘗試

對象類低於....

#import "TabView.h" 


@implementation TabView 


- (id)initWithFrame:(CGRect)frame { 
    if ((self = [super initWithFrame:frame])) { 
     UILabel *myLabel = [[UILabel alloc] initWithFrame:CGRectMake(50, 100, 200, 100)]; 
     myLabel.text = @"Stupid"; 
     [myLabel release]; 

    } 
    return self; 
} 

/* 
// Only override drawRect: if you perform custom drawing. 
// An empty implementation adversely affects performance during animation. 
- (void)drawRect:(CGRect)rect { 
    // Drawing code 
} 
*/ 

- (void)dealloc { 
    [super dealloc]; 
} 


@end 

父類

#import "TabbarviewViewController.h" 
#import "TabView.h" 
@implementation TabbarviewViewController 



/* 
// The designated initializer. Override to perform setup that is required before the view is loaded. 
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { 
    if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) { 
     // Custom initialization 
    } 
    return self; 
} 
*/ 

/* 
// Implement loadView to create a view hierarchy programmatically, without using a nib. 
- (void)loadView { 
} 
*/ 



// Implement viewDidLoad to do additional setup after loading the view, typically from a nib. 
- (void)viewDidLoad { 
    [super viewDidLoad]; 
    [self.view removeFromSuperview]; 
    TabView *mytab=[[TabView alloc]init ]; 
    NSLog(@"%@",mytab); 


} 



/* 
// Override to allow orientations other than the default portrait orientation. 
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
    // Return YES for supported orientations 
    return (interfaceOrientation == UIInterfaceOrientationPortrait); 
} 
*/ 

- (void)didReceiveMemoryWarning { 
    // Releases the view if it doesn't have a superview. 
    [super didReceiveMemoryWarning]; 

    // Release any cached data, images, etc that aren't in use. 
} 

- (void)viewDidUnload { 
    // Release any retained subviews of the main view. 
    // e.g. self.myOutlet = nil; 
} 


- (void)dealloc { 
    [super dealloc]; 
} 

@end 

回答

1

你必須調用initWithFrame在這條線TabView *mytab=[[TabView alloc]init ];,而不是init

+0

可以與你的示例代碼 – 2011-02-10 13:20:25

0

你忘了嗎[自addSubview:myLabel]在-initWithFrame:在TabView的類