STUPID PROGRAMMER
STUPID PROGRAMMER

Reputation: 523

How to alloc object class?

I am trying to alloc an object class with some button on it but unable to display data on parent class view

here what i m trying

Object Class is below....

#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

Parent Class

#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

Upvotes: 0

Views: 267

Answers (2)

tux91
tux91

Reputation: 1684

You forgot to do [self addSubview:myLabel] in -initWithFrame: in the TabView class

Upvotes: 0

Daniel A. White
Daniel A. White

Reputation: 190976

You have to call initWithFrame on this line TabView *mytab=[[TabView alloc]init ]; instead of init.

Upvotes: 1

Related Questions