-1

Possible Duplicate:
Objective C: Sending arguments to a method called by a UIButton

i have a problem with uibutton action. I want send argument when the button clicked. i saw some examples that work with tag prop. and the class is id sender. but i dont want to fixed it. the action goes to my own manager. how can i do ?

UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
    [rightButton addTarget:self
                    action:@selector(goToSubViewManager:)
          forControlEvents:UIControlEventTouchUpInside];

here is the gotosubviewmng

- (void)goToSubViewManager:(ViewType*)vTipi
{


}
Community
  • 1
  • 1
Emre Ekşioğlu
  • 359
  • 2
  • 13
  • 1
    It doesn't matter what you want to do: when UIButton detects an open arg in it's action, it sends itself through, which is why so much code uses `(id)sender`. Even explicitly stating that you will accept only objects of type ViewType is not a deterrent, you'll simply get a UIButton instance passed through to your method. – CodaFi Jan 04 '13 at 09:22
  • change - (void)goToSubViewManager:(ViewType*)vTipi to - (void)goToSubViewManager:(id)sender. – Anoop Vaidya Jan 04 '13 at 09:26
  • i want to send two parameter when the button clicked. if i fill only fill tag properties, it will performed too slow. – Emre Ekşioğlu Jan 04 '13 at 12:29

2 Answers2

1

you should only use - (void)goToSubViewManager:(id)sender. or - (void)goToSubViewManager

so here are 2 ways to solve your problem.

  1. you can use variables or property.
- (void)yourMethod

    {
        //your code
        _vTipi = yourVTipi;
    }
- (void)goToSubViewManager
{
    //here you can use _vTipi;
}
  1. you can add a Category for the UIButton , to add an id type property(such as @property(nonatomic) vTipi).faking instance variables for UIButton.(how to do you can look at this : http://oleb.net/blog/2011/05/faking-ivars-in-objc-categories-with-associative-references/) Then you can use like this:
- (void)goToSubViewManager:(id)sender
{
    //you can user ((UIButton *)sender).vTipi
}
Guo Luchuan
  • 4,729
  • 25
  • 33
0

Use can use tag property of the button. And then can use that object by comparing the tag assigned.

UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
    [rightButton addTarget:self
                    action:@selector(goToSubViewManager:)
          forControlEvents:UIControlEventTouchUpInside];
rightButton.tag=1;
//

then in the call back you can compare it as

- (void)goToSubViewManager:(id)sender
{
     if(sender.tag==1){
// you can use an array of that object(if multiple), then apply your logic
}

}
HDdeveloper
  • 4,396
  • 6
  • 40
  • 65