Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 03-18-2010, 02:47 PM   #1 (permalink)
Registered Member
 
Join Date: Dec 2009
Posts: 10
joeprogrammer is on a distinguished road
Default UI button not showing - please help

I have an interesting problem. When I add a UIImageView it works fine

This code works:
- (void) showAd {

CGRect myAdRect = CGRectMake(0.0f, 0.0f, 320.0f, 480.0f);
UIImageView *myAd = [[UIImageView alloc] initWithFrame:myAdRect];
[myAd setImage:[UIImage imageNamed:@"Empty Red Box.png"]];
myAd.alpha = 0.0f;
[self.view addSubview:myAd];

CGContextRef context = UIGraphicsGetCurrentContext();
[UIView beginAnimations:nil context:context];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:0.3];
myAd.alpha = 1.0f;
myAdButton.alpha = 1.0f;
[UIView commitAnimations];

[myAd release];
}


BUT, when I try to do something very similar adding a UIButton like this:
- (void) showAd {

//create button
UIButton *myButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
myButton.frame = CGRectMake(100,200, 100, 50); // position in the parent view and set the size of the button
[myButton setTitle:@"Click Me!" forState:UIControlStateNormal];
//add targets and actions
[myButton addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
// add to a view
[self.view addSubview:myButton];

[myButton release];
}


It doesn't work. By doesn't work, I mean no button appears on the screen. I have no idea what I could be doing wrong.

Ideas?
joeprogrammer is offline   Reply With Quote
Old 03-19-2010, 05:17 AM   #2 (permalink)
Mobile and Web solutions
 
hello24's Avatar
 
Join Date: May 2009
Location: London, UK
Posts: 72
hello24 is on a distinguished road
Send a message via Skype™ to hello24
Default

Can you check if myButton is not nil before you add it to the subview?

Also, can you try adding a retain when creating the button:
UIButton *myButton = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain];

Can't explain why you would want to retain yet but the BubbleLevel example shipped with the documentation seems to be doing that.
hello24 is offline   Reply With Quote
Old 03-24-2010, 03:52 PM   #3 (permalink)
Registered Member
 
Join Date: Jun 2009
Posts: 59
computermatt is on a distinguished road
Default

You might want to have put this in the iphone section, not the osx section. Last time I checked, UI = iPhone, NS = osx
computermatt is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 463
15 members and 448 guests
alexeir, David-T, Dj_kades, foslock, iAppDeveloper, jeroenkeij, mer10, Mijator, myach, pipposanta, QuantumDoja, robsmy, sacha1996, SLIC, usernametaken
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,679
Threads: 94,129
Posts: 402,928
Top Poster: BrianSlick (7,990)
Welcome to our newest member, xzoonxoom
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 09:29 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0