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

Mockup & CodeGen, iPhone & iPad
($9.99)

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

Manu
($0.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 01-14-2010, 12:07 PM   #1 (permalink)
Registered Member
 
Join Date: Jan 2010
Posts: 2
Question HOW?: create a dynamic UIButton

i am working on a quiz game app... but i want the UIButtons to be dynamicly filled from the table of answers.

i am very new to iphone dev and development in general... only been working with objective-c for about a month.

i have tried "UIButton.text =" this is surely a beginners mistake
could anyone point me in the right direction?

Thanks in advance for any help!
Ironcladmvtm is offline   Reply With Quote
Old 01-14-2010, 01:10 PM   #2 (permalink)
Dr. Touch Cocoa Helpdesk
iPhone Dev SDK Supporter
 
Join Date: Sep 2008
Location: Vienna, Austria
Posts: 537
Send a message via AIM to Oliver Drobnik Send a message via MSN to Oliver Drobnik Send a message via Skype™ to Oliver Drobnik
Default

Quote:
Originally Posted by Ironcladmvtm View Post
i am working on a quiz game app... but i want the UIButtons to be dynamicly filled from the table of answers.

i am very new to iphone dev and development in general... only been working with objective-c for about a month.

i have tried "UIButton.text =" this is surely a beginners mistake
could anyone point me in the right direction?

Thanks in advance for any help!

Depends what kind of button, you can also combine it with foreground and background images.

But a simple button you create programmatically:

Code:
UIButton *oneButton = [UIButton buttonWithType:UIButtonTypeRoundedRect]; // autoreleased
then you set the text:

Code:
[oneButton setTitle:@"Text" forState:UIControlStateNormal];
finally you need to add the button to the a view so that it get's displayed and retained.

Code:
[anyView addSubview:oneButton];
ah and you might want to set the button's dimensions. You can do this before or after the addSubview:

Code:
oneButton.frame = CGRectMake(x, y, w, h);

the buttonWithType class methods makes a autoreleased instance, the addSubview increases retain count to two. Then the autorelease pool draining reduces it to one.

when you finally call

Code:
[oneButton removeFromSuperview];
it disappears both from the screen as well as memory because this decreases the retainCount to 0 = dealloc.
__________________
regards

Oliver Drobnik
Cocoanetics - Our DNA is programmed in Objective-C.

Linguan – makes localizing strings file fun!

Cocoanetics Parts Store – easy to use yet professionally looking components that you can use to spruce up your own apps. Augmented Reality, Calendar Control, Pin Lock or Purchase Button are only some examples. You get full source code, no static library crap, and lifetime support. Check it out today!
Oliver Drobnik is offline   Reply With Quote
Old 01-14-2010, 03:44 PM   #3 (permalink)
Registered Member
 
Join Date: Jan 2010
Posts: 2
Default

Quote:
Originally Posted by Oliver Drobnik View Post
Depends what kind of button, you can also combine it with foreground and background images.

But a simple button you create programmatically:

Code:
UIButton *oneButton = [UIButton buttonWithType:UIButtonTypeRoundedRect]; // autoreleased
then you set the text:

Code:
[oneButton setTitle:@"Text" forState:UIControlStateNormal];
finally you need to add the button to the a view so that it get's displayed and retained.

Code:
[anyView addSubview:oneButton];
ah and you might want to set the button's dimensions. You can do this before or after the addSubview:

Code:
oneButton.frame = CGRectMake(x, y, w, h);

the buttonWithType class methods makes a autoreleased instance, the addSubview increases retain count to two. Then the autorelease pool draining reduces it to one.

when you finally call

Code:
[oneButton removeFromSuperview];
it disappears both from the screen as well as memory because this decreases the retainCount to 0 = dealloc.
this makes since to me but it is still not working I'm using .xibs to create my application so the button is already created and linked via interface builder and i added the code
Code:
 [answerOne setTitle:@"text" forState:UIControlStateNormal];
but the text still does not show up.... very strange to me because the program still functions normally like it is just skipping that line of code? should i link it to a label in the accessibility section in interface builder?
Ironcladmvtm is offline   Reply With Quote
Reply

Bookmarks

Tags
custom uibutton text, uibutton, uibutton text

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: 264
15 members and 249 guests
@sandris, ADY, Alsahir, dacapo, Dani77, Desert Diva, djohnson, HemiMG, jansan, JasonR, MarkC, prchn4christ, smethorst, tomtom100
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,882
Threads: 89,228
Posts: 380,762
Top Poster: BrianSlick (7,129)
Welcome to our newest member, jansan
Powered by vBadvanced CMPS v3.1.0

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