2011-02-10 89 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的类