PDA

View Full Version : buttons not appearing in view




stoopkitty
Apr 21, 2011, 04:21 PM
Hi, I am having some problems with getting UIButtons to appear in my app. In my code, I have made 9 buttons (also some other UI elements), and initialized all of them in loadView. This works up to a point, except a few (4 to be exact) buttons never appear in the view. If you know of anything that could be causing this, please leave me a response. thanks!!

Things I have tried:

adding everything to view in viewDidLoad.
Not using images for the buttons.
Making sure the buttons are set to hidden=NO
switching up the order that i create each button (it is always the same 4 that do not appear)
Changing other UI elements to make sure that it is not just running an old build of my program over and over again.
setting the buttons location to a different place including on the main screen. (NOTE: When the app starts up, i have a set of buttons on the left and a set on the right (offscreen) and it slides back and forth between screens but you can still see some of the buttons on the right screen, its just those 4 that you cant see.


Code (if you need other code please tell me):
For a working button:
in .h i initialize and set @property
UIButton *slideLeftButton;
...
@property (nonatomic, retain) IBOutlet UIButton *slideLeftButton;


in .m i @synthesize, then i set up button and add to view
@synthesize ... slideLeftButton, ...
...
//slideLeftButton slides left
slideLeftButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
slideLeftButton.frame = CGRectMake(340, 248, 130, 50);
[slideLeftButton setTitle:@"<-- Input" forState:UIControlStateNormal];
[slideLeftButton setTitle:@"<-- Input" forState:UIControlStateHighlighted];
filepath = [[NSBundle mainBundle] pathForResource:@"button-half@2x" ofType:@"png"];
[slideLeftButton setBackgroundImage:[UIImage imageWithContentsOfFile:filepath] forState:UIControlStateNormal];
filepath = [[NSBundle mainBundle] pathForResource:@"button-halfDown@2x" ofType:@"png"];
[slideLeftButton setBackgroundImage:[UIImage imageWithContentsOfFile:filepath] forState:UIControlStateHighlighted];
[slideLeftButton setTitleColor:[UIColor darkTextColor] forState:UIControlStateHighlighted];
[slideLeftButton addTarget:self action:@selector(slideLeft) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:slideLeftButton];


For a non-working button:
in .h i initialize and set @property
UIButton *shareWithFacebookButton;
...
@property (nonatomic, retain) IBOutlet UIButton *shareWithFacebookButton;


in .m i @synthesize, then i set up button and add to view
@synthesize ... shareWithFacebookButton, ...
...
//shareWithFacbook button calls shareWithFacebook
shareWithFacebookButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
shareWithFacebookButton.frame = CGRectMake(490, 306, 130, 50);
[shareWithFacebookButton setTitle:@"Facebook" forState:UIControlStateNormal];
[shareWithFacebookButton setTitle:@"Facebook" forState:UIControlStateHighlighted];
filepath = [[NSBundle mainBundle] pathForResource:@"button-half@2x" ofType:@"png"];
[shareWithFacebookButton setBackgroundImage:[UIImage imageWithContentsOfFile:filepath] forState:UIControlStateNormal];
filepath = [[NSBundle mainBundle] pathForResource:@"button-halfDown@2x" ofType:@"png"];
[shareWithFacebookButton setBackgroundImage:[UIImage imageWithContentsOfFile:filepath] forState:UIControlStateHighlighted];
[shareWithFacebookButton setTitleColor:[UIColor darkTextColor] forState:UIControlStateHighlighted];
[shareWithFacebookButton addTarget:self action:@selector(shareWithFacebook) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:shareWithFacebookButton];