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 07-25-2008, 01:58 PM   #1 (permalink)
New Member
 
Join Date: Jul 2008
Posts: 3
granbajo is on a distinguished road
Default Unable to setImage for UIButton

I am new to Objective C and iPhone development.

I am trying to write a little yahtzee type application for my iPod Touch. I have decided to use UIButtons with images to show the dice.

I created the interface using IB and set up the buttons as outlets which created this in the h file:

...
IBOutlet UIButton *buttonD1;
IBOutlet UIButton *buttonD2;
...

I also added this to the h file:

// Images
UIImage *d1Image;
UIImage *d2Image
...

Then on the m file I have this:

* (void)awakeFromNib {
self addSubview:boardView;
d1Image = IImage imageNamed:@"d1.png";
buttonD1 setBackgroundImage:d1Image forState:UIControlStateNormal;
}

Nothing happens!

The image is in my bundle, I can assign it to the button in IB, but not if I want to do it programatically. Any ideas?

Thanks

Last edited by granbajo; 07-25-2008 at 02:00 PM.
granbajo is offline   Reply With Quote
Old 07-25-2008, 04:06 PM   #2 (permalink)
I can't think without pen
 
Join Date: Jul 2008
Location: New York
Posts: 72
aahmed753 is on a distinguished road
Default

shouldn't you get compiler error with the code u listed? you are missing the [] for the method call:
buttonD1 setBackgroundImage:d1Image forState:UIControlStateNormal;

it should be:
[buttonD1 setBackgroundImage:d1Image forState:UIControlStateNormal];
aahmed753 is offline   Reply With Quote
Old 07-25-2008, 05:58 PM   #3 (permalink)
New Member
 
Join Date: Jul 2008
Posts: 3
granbajo is on a distinguished road
Default

Sorry, it is not missing from my code... it looks like this...

Code:
- (void)awakeFromNib {
	
	[self addSubview:boardView];
	d1Image = [UIImage imageNamed:@"D1.png"];
	[buttonD1 setImage:d1Image forState:UIControlStateNormal];
	[d1Image release];
}
granbajo is offline   Reply With Quote
Old 07-25-2008, 06:14 PM   #4 (permalink)
New Member
 
Join Date: Jul 2008
Posts: 3
granbajo is on a distinguished road
Default

I have been going about this for the last 3 days, and I finally figured out. There was nothing wrong in the code, I had forgotten to link the outlets with the buttons in IB.
granbajo is offline   Reply With Quote
Old 07-25-2008, 07:18 PM   #5 (permalink)
Senior Member
 
MaCeXpErTo's Avatar
 
Join Date: Jul 2008
Posts: 149
MaCeXpErTo is on a distinguished road
Default

Quote:
Originally Posted by granbajo View Post
I have been going about this for the last 3 days, and I finally figured out. There was nothing wrong in the code, I had forgotten to link the outlets with the buttons in IB.
That's funny, because I was going to ask you if you have did that or not. lol but I figured you did so I didn't bother to ask you if you have or not. wow my bad... Next time I'll ask questions and won't hesitate.
MaCeXpErTo is offline   Reply With Quote
Old 12-17-2009, 04:31 AM   #6 (permalink)
Registered Member
 
Join Date: Aug 2009
Posts: 58
ziophase is on a distinguished road
Default

Quite hilarious, because I was having the exact same problems, and of all things, I'd forgotten to connect in IB too!
Thanks to this thread!
ziophase is offline   Reply With Quote
Old 02-19-2010, 10:53 PM   #7 (permalink)
Registered Member
 
Join Date: Jan 2009
Location: Atlanta
Posts: 411
funkytaco is on a distinguished road
Thumbs up

Quote:
Originally Posted by ziophase View Post
Quite hilarious, because I was having the exact same problems, and of all things, I'd forgotten to connect in IB too!
Thanks to this thread!
Sigh, ditto.
funkytaco is offline   Reply With Quote
Old 02-20-2010, 05:30 AM   #8 (permalink)
Registered Member
 
Join Date: Feb 2010
Posts: 1
tacet is on a distinguished road
Default

This is a little bit off-topic (very basic but always confusing) question:

I'm wondering if "setImage:" method copies(or retains) the "d1Image",
and also wondering if the last code "d1Image release" is necessary.
(since "d1Image" will be auto-released?)

Code:
- (void)awakeFromNib {
	
	[self addSubview:boardView];
	d1Image = [UIImage imageNamed:@"D1.png"];
	[buttonD1 setImage:d1Image forState:UIControlStateNormal];
	[d1Image release];
}
tacet 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: 337
6 members and 331 guests
givensur, ipodphone, jbro, mer10, n00b, yomo710
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,649
Threads: 94,113
Posts: 402,881
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Anwerbl
Powered by vBadvanced CMPS v3.1.0

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