views:

252

answers:

2

So I am making an iPhone program and for some odd reason the title of my UIButtons will not show... am I missing something??

I get no errors or even warnings on compilation and my buttons and everything appear, just the title is not being shown....

FurballViewController.m

...

-(void)loadView {

  UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
  [btn setFrame:CGRectMake(20, 50, 280, 40)];
  [btn setTitle:@"Stupid Title Wont Work" forState:UIControlStateNormal];
  [self.view addSubview:btn];
  [btn release];

}

...

A: 

Did you try to set the title text color? It could be white.

kovpas
Shouldn't be necessary. UIButtonTypeRoundedRect sets a default dark-bluish color.
Noah Witherspoon
A: 

i figured it out guys. I released the btn. I suppose when an object is initialized without alloc you dont release it. This code works:

FurballViewController.m

...

-(void)loadView {

  UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
  [btn setFrame:CGRectMake(20, 50, 280, 40)];
  [btn setTitle:@"Stupid Title Wont Work" forState:UIControlStateNormal];
  [self.view addSubview:btn];
  //[btn release];

}

...

Dick Savagewood
sure... you used (+) class method.. which has autorelease method. you don't need to release it.
Yoon Lee