views:

55

answers:

2

in xxx.h

UIButton *b1, *b2, *b3;

in xxx.m

b1 = ---- similarly for b2 and b3

Now I want that on Click event I store the title in the string. How i can achieve it?

In Other Words: What function/method would I have to implement in my View Controller class to handle a click event on a UIButton?

+1  A: 

You can make an IBAction for touch up inside in Interface Builder. Then I am assuming you have a UITextField for the text.

Since your not using Interface Builder you need to:

-(void)getStringFromText:(id)sender {
    NSString *input = sender.titleLabel;
}



//In some start up method.
[b1 addTarget: target action: @selector(getStringFromText:) forControlEvents: UIControlEventTouchUpInside];
thyrgle
@thyrgl, I am not using Interface Builder. So, sugest some other solution. Please in detail because i am newbie.
@thyrgl, I tried it but there is a problem. I have more then 1 button or you can say i have an array of buutons. So i am trying this in a loop. So, the string to which i am giving the title always holds for last button.
@user: Then make more than 1 of `[b1 addTarget: target action: @selector(getStringFromText:) forControlEvents: UIControlEventTouchUpInside];` just replace `b1` with the name of the button.
thyrgle
A: 

When you declare your UIButtons, you need to put "IBOutlet" before them in your class definition - then you need to to use Interface Builder to link/reference the UIButtons to the ones you have declared in your code.

Once you have done this, you need to develop a (IBAction) method - and have it simply get the "text" property from the calling object. In Interface Builder reference this method for all the buttons for the "touch up" event.

If this isn't clear I will post up code as an example?

EnOpenUK
Yes Put the code. But I am not using the Interface builder. Because I am not creating buttons using interface builder. So it still works. If yes then put the code. Thanx