0

I have a value called member id and I want to send it to another view controller, If I place the following in didSelectRowAtIndexPath, The value passes to the variable "member".

int memberIndex = [indexPath indexAtPosition: [indexPath length] - 1];
    member = [[tableDataSource2 objectAtIndex: memberIndex] objectForKey:@"Memberid"];

If it is placed in the cellForRow, of course it rewrites with every row created. I have a button in each row that launches a viewController, I want the button action to grab the rows "member" and pass it to the new controller. Is there a "didSelectButton at index path method" or a way to grab that on the fly?

any Ideas would be great. It's the first time I'm adding a button to a UiTableview.

Thanks

Michael Robinson
  • 1,439
  • 2
  • 16
  • 23

2 Answers2

1

Why not use the accessory view? It is a built-in button that you can skin with any image you want to give the UI any kind of feel that is required. Then add this to the table's delegate:

accessoryButtonTappedForRowWithIndexPath: (NSIndexPath *) indexPath{ ... }

You will then be able to call your method on your table data source and launch your secondary view.

MystikSpiral
  • 5,018
  • 27
  • 22
  • How is this supposed to work? The documentation on this method clearly states "This method is not called when an accessory view is set for the row at indexPath. " Indeed, in my case the method does not get called if I set a custom button as the accessory view. – Katlu Oct 17 '12 at 14:54
0

Just play with "tag".

Each UIView has an attribute tag (int).

in the cellForRowAtIndexPath :

//create yourButton and then
yourButton.tag = memberIndex;

and when you are using an IBAction just get the sender :

- (IBAction) didSelectButton:(id)sender
{
int memberIndex = ((UIButton *)sender).tag;
//
}

tips : to get the sender when you are setting the action property of your button don't forget the ":"

E.G

action = @selector(didSelectButton:);
Francescu
  • 16,974
  • 6
  • 49
  • 60