Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS

BUILD A SIMPLE IPHONE APP, MAKING IT PRETTY = EXTRA CREDIT

Can someone kindly tell me how to complete the following task:

"Delete the button from the Storyboard and try to add it programmatically within the viewDidLoad method.

Set an image for the button using its background image property and then set the title text. This should allow you to change the text of your button without having to change the image."

When I attempted it by button when to the top and when I pressed the button nothing happened.

Thank You

3 Answers

Hi im having a similar problem to this..

I have tried searching and have so far got this:

[super viewDidLoad];

UIImage *button = [UIImage imageNamed:@"PredictButton.png"];
UIImage *buttonOff = [UIImage imageNamed:@"PredictButtonOff.png"];
UIImageView *buttonView = [[UIImageView alloc] initWithImage:button highlightedImage:buttonOff];
buttonView.userInteractionEnabled = YES;
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(imageTapped)];
[buttonView addGestureRecognizer:tap];
buttonView.frame = CGRectMake(20, 380, 280, 40);
[self.view insertSubview:(buttonView) atIndex:0];

(*Also need to find out how it will link to change the predictionArray and change the predictionLabel.text)

Im stuck where to go next as trying to link the touchGesture so it enables the highlighted version?

To be honest i think ive made things a little too complicated already...

Thanks..

Sam

Amit Bijlani
Amit Bijlani
Treehouse Guest Teacher

You are making this complicated. You should use UIButton which is what it is meant for if you want interaction.

Eduardo Rojas
Eduardo Rojas
4,084 Points

What am i doing wrong?

UIButton *btnDemo = [UIButton buttonWithType:UIButtonTypeRoundedRect]; btnDemo.frame = CGRectMake(100, 100, 100, 100); [btnDemo setTitle:@"Show Alert" forState:UIControlStateNormal];

[btnDemo addTarget:self action:@selector(touchUpHandler:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btnDemo];

My Error Says Undeclered Selector touchUpHandler

Amit Bijlani
Amit Bijlani
Treehouse Guest Teacher

The error means that you have not implemented a method with the name touchUpHandler. Essentially, you want to call a method when a user taps the button. In this case, it could be the makePrediction method.