Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

hotkarl

macrumors newbie
Original poster
Nov 19, 2010
29
1
Northern Utah
I have a whole bunch of buttons with the following action attached. I would like to include, in this action, an opacity change of the button. I thought maybe self.alpha or sender.alpha but it won't work. I'm just learning and would love some help.

Code:
-(IBAction) clicked:(id)sender {
	NSString *titleForButton = [sender titleForState: UIControlStateNormal];
	NSString *imagePath = [[NSString alloc] initWithFormat:@"%@.jpg", titleForButton];
	NSString *musicPath = [[NSString alloc] initWithFormat:@"%@.mp3", titleForButton];
	[COLOR="Red"]?.alpha = .2;[/COLOR]
	tab.text = imagePath;
	music.text = musicPath;
}
 
What didn't work with sender.alpha? sender should a pointer to the object that sent the message. Did you get a compiler warning? Or did it not work at runtime?
 
I get attached failed message.
 

Attachments

  • Screen shot 2010-11-19 at 2.57.12 PM.png
    Screen shot 2010-11-19 at 2.57.12 PM.png
    35.1 KB · Views: 89
Thank you! I owe you a cheeseburger. Is there a particular article I should read to become familiar with that idea?

Thanks again.
 
Thank you! I owe you a cheeseburger. Is there a particular article I should read to become familiar with that idea?

Thanks again.

It's basic C. You did learn C before Objective-C right? id is a shorthand for void *. Clearly that is untyped (effectively) so the compiler gives warnings about unrecognised messages.
 
No man. I've never done any programming. I am reading Programming in Objective-C 2.0 by Kochan and watching the iPhone tutorials at thenewboston.com. I'm brand new to all of this. Objective C is my first programming language.
 
No man. I've never done any programming. I am reading Programming in Objective-C 2.0 by Kochan and watching the iPhone tutorials at thenewboston.com. I'm brand new to all of this. Objective C is my first programming language.

There are two trains of thought on here (and a thread about it). I say you should learn C before Objective-C. Others say it's not required. Then something like this happens and I think I'm right.
 
Perhaps I will learn C as well. If it considered to be a prerequisite then I had probably ought to figure it out.

Thank you once again.
 
[sender setAlpha:0.2]; worked fine as well.

Thanks!

I am trying to figure out how to make the current button's alpha go back to normal when the next button is clicked by doing what robbieduncan said and somehow keeping a reference of the current button. If I can't get it on my own I may be back here to get some more advice from all you super gurus.

Thanks again.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.