Note that there are some explanatory texts on larger screens.

plurals
  1. POuitabelview custom button tag issue
    text
    copied!<p>I am creating a custom button in my uitable and giving the button a tag number as shown in code below.</p> <pre><code>// Customize the appearance of table view cells. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { //NSLog(@"Inside cellForRowAtIndexPath"); static NSString *CellIdentifier = @"Cell"; // Try to retrieve from the table view a now-unused cell with the given identifier. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; // If no cell is available, create a new one using the given identifier. if (cell == nil) { // Use the default cell style. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier]; button = [UIButton buttonWithType:UIButtonTypeCustom]; [button addTarget:self action:@selector(selectPicOnBtnTouch:) forControlEvents:UIControlEventTouchDown]; [button setTitle:@"btn1" forState:UIControlStateNormal]; button.frame = CGRectMake(6.0f, 0.0f, 97.0f, 110.0f); button.tag = (indexPath.row)+100; [cell addSubview:button]; [button setImage:[UIImage imageNamed:@"sample_pic.png"] forState:UIControlStateNormal]; } else { //NSLog(@"went here 2"); button = (UIButton *) [cell viewWithTag:((indexPath.row)+100)]; } //Get an arrow next to the name cell.accessoryType = UITableViewCellAccessoryNone; return cell; } - (IBAction) selectPicOnBtnTouch:(id)sender { button = (UIButton *)sender; NSLog(@"[button tag]: %d ...", [button tag]); } </code></pre> <p>If I have a table with 10 rows and when I touch buttons in rows 1-5 I get the following in my log</p> <pre><code>[button tag]: 100 ... [button tag]: 101 ... [button tag]: 102 ... [button tag]: 103 ... [button tag]: 104 ... </code></pre> <p>This is fine. The problem is that when I touch row 6-10 I am expecting 105 - 109 tags but what I get back is same tag numbers starting over </p> <pre><code>[button tag]: 100 ... [button tag]: 101 ... [button tag]: 102 ... [button tag]: 103 ... [button tag]: 104 ... </code></pre> <p>The reason I want to keep the tag numbers unique (and not repeating) is so that I know which button corresponds to what row. How can I do that? </p>
 

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