开发者

Passing a value on a IBAction button method in a UITableview Row

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: [in开发者_JS百科dexPath 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


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.


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:);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜