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 03-24-2010, 01:16 AM   #1 (permalink)
Registered Member
 
Join Date: Jul 2009
Posts: 3
gamemasta0 is on a distinguished road
Default buttonPressed(id)sender using a key to change a buttons state

I am looking into how to access a variable within my class using text as its name. The only solution I have found so far to do so is using an NSDictionary and assigning that particular object a key. Using this method, I have added eight UIButtons (declared in the header as: 'IBAction UIButton *button1' etc...) and assigned them keys (such as: 'button1, @"button1s", button2, @"button1d", ...') in a new NSDictionary that is global and is named buttonsDict. I am now trying to access and change a property in a button in that NSDictionary based on the name of a button created in the Interface Builder's title. The titles are all following this example: '1s'. Once appending the word 'button' to the string of the title of the button it should return something like: 'button1s'. The method I am trying to do this is as follows:

Code:
-(IBAction)buttonPress:(id)sender {
	NSString *temp = @"button";
	temp = [temp stringByAppendingString:[sender titleForState:UIControlStateNormal]];
	UIButton *button = [buttonDict objectForKey:temp];
	button.hidden = YES;
	[buttonDict setValue:button forKey:temp];
}
I am relatively new at iPhone programming and am not sure why the run of this particular program exits with message 'EXC_BAD_ACCESS' at the line of the creation of 'button' when I press any button in the simulator. Any ideas?
Attached are the class files Where this method came from, if that helps...
Attached Files
File Type: zip Classes.zip (5.2 KB, 2 views)
gamemasta0 is offline   Reply With Quote
Old 03-24-2010, 01:31 AM   #2 (permalink)
Registered Member
 
Join Date: Jul 2009
Posts: 3
gamemasta0 is on a distinguished road
Default

Adding to this: I tried a last-resort method, initializing the dictionary every time the method is run. This got rid of the 'EXC_BAD_ACCESS' but then caused the error: '*** -[NSCFDictionary setObject:forKey:]: mutating method sent to immutable object' on the line where I setValue:forKey:. Ideas?
gamemasta0 is offline   Reply With Quote
Reply

Bookmarks

Tags
builder, interface, nsdictionary, 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: 347
11 members and 336 guests
akacaj, c2matrix, cgokey, esoteric, givensur, HemiMG, Mirotion22, mjnafjke, Pudding, SLIC, Techgirl-52
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,651
Threads: 94,115
Posts: 402,887
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Mirotion22
Powered by vBadvanced CMPS v3.1.0

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