Tuesday, 6 October 2015

uitableview get indexpath to uibutton

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    AccessUsersCell *cell = (AccessUsersCell *) [tableView dequeueReusableCellWithIdentifier :CellIdentifier];
    if (cell == nil)
    {
        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"AccessUsersCell" owner:self options:nil];
        cell = [nib objectAtIndex:0];
        cell.btnSelect.tag = indexPath.row + 1;
        [cell.btnSelect addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
        
    }
    
    return cell;

}


- (UITableViewCell *)containingCellForView:(UIView *)view
{
    if (!view.superview)
        return nil;

    if ([view.superview isKindOfClass:[UITableViewCell class]])
        return (UITableViewCell *)view.superview;

    return [self containingCellForView:view.superview];
}

- (void)buttonClicked:(id)sender
{
    UITableViewCell *containingCell = [self containingCellForView:sender];
    if (containingCell) {
        NSIndexPath *indexPath = [tableName indexPathForCell:containingCell];
        NSLog(@"Section: %i Row: %i", indexPath.section, indexPath.row);
    }
}

No comments:

Post a Comment