Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

HELP: with UIButton actions (new to objective c and iphone dev)



i am new to objective c and iphone dev and have been working through examples. I am trying to build a simple iphone Calculator to help me learn.

The situation:

- I have 10 UIbuttons with setTitles of 0 through to 9, these display correctly in the iphone simulator. 
- I have a UILabel which I want to display the input from the 10 buttons.

The problem:

How do I pass arguments ( ie the button number 0-9, or in future pi (3.142)  ) to a method using the addTarget: action: syntax

Button code as follows:

//button one
UIButton * alloc] initWithFrame:genericButtonFrame];

    [oneButton setTitle:@"1" forStates:UIControlStateNormal];
oneButton.font = [UIFont boldSystemFontOfSize:BUTTON_FONT_SIZE];
    oneButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    oneButton.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
   
[oneButton setBackgroundImage:genericImage forStates:UIControlStateNormal];
[oneButton setBackgroundImage:buttonBackgroundPressed forStates:UIControlStateHighlighted];

NSString *test = @"1";

[oneButton addTarget:self action:@selector(insertButtonValue:???????????) forControlEvents:UIControlEventTouchUpInside];  //hello: is sent when the button is touched
oneButton.center = CGPointMake( 45.0, 240.0);
oneButton.backgroundColor = [UIColor clearColor];
    [aContentView addSubview:oneButton];
    [oneButton release];

//button two etc etc etc


Method to be called:

- (void) insertButtonValue: (NSString *) valueSentFromButton
{
NSString *buttonValue = [NSString stringWithFormat:@"button sent %@!", valueSentFromButton];
self.label.text = buttonValue;
}

Obviously the numeric buttons will all have different values, and I don't want to call a separate method  for each one. I have tried loads of ways of specifying it and each time meet with various compiler errors. Starting to go MAD!!

With the code as is  ( obviously no ????? ) the method is receiving an object reference to the UIButton, can I set a values within the UIButton object??? All help greatly appreciated.

Thanks

Matt

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Objc-language mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/objc-language/email@hidden

This email sent to email@hidden



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.