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 12-13-2010, 08:34 AM   #1 (permalink)
Registered Member
 
Join Date: Dec 2010
Posts: 2
TomCuthill is on a distinguished road
Default Button tag problem

I have created buttons each with their own tag.

Code:
int tag;
	for (int i = 0; i < N_COLS; i++) {
		for (int j = 0; j < N_ROWS; j++) {
			soundButton = [UIButton buttonWithType:UIButtonTypeCustom];
			soundButton.frame = CGRectMake(i * 20.0, j * 20.0, 20.0, 20.0);
			tag=j + i * N_ROWS + 1;
			soundButton.tag = tag;
			buttonStatus[tag] = NO;
			[soundButton setImage:[UIImage imageNamed:@"BWhite2.png"]
					 forState:UIControlStateNormal];
			[soundButton addTarget:self action:@selector(buttonPushed:)
			  forControlEvents:UIControlEventTouchUpInside];
			[self.view addSubview:soundButton];			
		}
}
I have used the tags in the buttonPushed: method.

Code:
- (void) buttonPushed:(id)sender {
	UIButton *soundbutton = sender;
	NSLog(@"buttonPushed tag=%d", soundbutton.tag);
	
	int tag = soundbutton.tag;
	
	buttonStatus[tag] = !buttonStatus[tag];
	
	NSLog(@"Status=%d", buttonStatus[tag]);
	
	if (buttonStatus[tag]==YES) {
		[soundbutton setImage:[UIImage imageNamed:@"BBlue.png"]forState:UIControlStateNormal];
	}
	else {
		[soundbutton setImage:[UIImage imageNamed:@"BWhite2.png"]forState:UIControlStateNormal];
	}

}
How do I use the tags in another method? I have searched elsewhere but could not find the answer.

Many thanks,
Tom.
TomCuthill is offline   Reply With Quote
Old 12-13-2010, 09:32 AM   #2 (permalink)
Senior Member
iPhone Dev SDK Supporter
 
Join Date: Aug 2008
Location: Memphis, TN, USA
Age: 24
Posts: 3,983
smithdale87 is on a distinguished road
Send a message via AIM to smithdale87
Default

How do you want to use them? You can get a particular button by it's tag like this:

Code:
UIButton* button = (UIButton*)[self.view viewWithTag: someTag];

if( button != nil )
{
    //do something with the button
}
smithdale87 is offline   Reply With Quote
Old 12-13-2010, 09:37 AM   #3 (permalink)
Registered Member
 
Join Date: Dec 2010
Posts: 2
TomCuthill is on a distinguished road
Default

I have a method which is incremented by a counter. And I want to check which buttons are pressed every time the timer counts.

Tom
TomCuthill is offline   Reply With Quote
Reply

Bookmarks

Tags
tag, uibutton

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: 381
7 members and 374 guests
chemistry, daudrizek, HemiMG, jeroenkeij, whitey99
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,665
Threads: 94,120
Posts: 402,898
Top Poster: BrianSlick (7,990)
Welcome to our newest member, daudrizek
Powered by vBadvanced CMPS v3.1.0

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