Saturday 18 February 2012

Get NSIndexPath on Custom Cell Button Tapped

Hello EveryBody,

For the UIButton of the Cell set the selector method as :

[theCell.button addTarget:self action:@selector(btnTapped:withEvent:) forControlEvents:UIControlEventTouchUpInside];

Now in selector method:

- (void)btnTapped:(id)sender withEvent:(UIEvent*)event {

          UITouch *touch = [[event touches] anyObject];
          CGPoint location = [touch locationInView:self.tableView];
          NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:location];
}

This is how we do it.

Thanks

Passing Multiple Parameters on UIButton action

Hello EveryBody,

One can pass multiple parameters on a single UIButton action as:

Just Make a Subclass of UIButton and have the parameters you want to pass in it.

Now when using the UIButton just pass the values to these parameters and access those parameters there.
Example:

MyCustomButton *urButton = [[MyCustomButton alloc] init];
urButton.urArg = arg;
[urButton addtarget:self action:@selector(urBtnTapped:) forControlEvents:UIControlEventTouchUpInside];

//      Implementation Part of Selector
- (void)urBtnTapped:(id)sender {

               UIButton *btn= (UIButton*)sender;
               argType *arg = btn.urArg;
}

In This way one can get multiple arguments.

Thanks