i am creating button dynamically. and creation action methods by
[newButton addTarget:self action:@selector(goToNew:)forControlEvents:UIControlEventTouchUpInside];
i want to send argument (indexpath.row) from tableview , but not want to use tag.. because i need that tag will remain same for all the buttons , how can i pass argument in button action ?
actually i am adding button in each tableview cell , and i want action for all those buttons , but if i use tag = indexpath.row and and use it with action, it works but problem of overlaying button happen.hence i want tag would be constant.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UIButton *btn;
UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
btn = [UIButton buttonWithType:UIButtonTypeCustom];
[btn addTarget:self action:@selector(goToNew:) forControlEvents:UIControlEventTouchUpInside];
btn.tag = 55;
[cell.contentView addSubview:btn];
}
else {
btn = (id)[cell.contentView viewWithTag:55];
}
return cell;
}
- (void) goToNew:(id)sender
{
UIButton *b = (UIButton *)sender;
UITableViewCell cell = (UITableViewCell)[b superview];
int row = [msgTableView indexPathForCell:cell].row;
(@"row is :::%d",row);
}