Quote:
Originally Posted by Ironcladmvtm
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!