Note that there are some explanatory texts on larger screens.

plurals
  1. POPassing argument in button action method without use of tag
    primarykey
    data
    text
    <p>i am creating button dynamically. and creation action methods by </p> <pre><code> [newButton addTarget:self action:@selector(goToNew:)forControlEvents:UIControlEventTouchUpInside]; </code></pre> <p>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 ? </p> <p>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.</p> <pre><code> - (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; </code></pre> <p>}</p> <pre><code>- (void) goToNew:(id)sender </code></pre> <p>{<br> <code>UIButton *b = (UIButton *)sender;<br> </code> UITableViewCell <em>cell = (UITableViewCell</em>)[b superview];<br> <code>int row = [msgTableView indexPathForCell:cell].row;<br> </code> (@"row is :::%d",row); </p> <pre><code>} </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload