Search code examples
iosuitableviewios7nsindexpath

How can I get touched text box index in table view cell in IOS 7


I want to get index of touched Text Box in tableview cell. The fact that I could do it before IOS 7. In the past I could get the text box index in below. This method also fails to IOS 7. I read tag should use instead of this method. But I also use tag for each different text box. Because Clicking to the text box I am doing different things, for example opening the picker or opening to the selection view. Plase help me, how can I get the row number of each text box When touched to text box.

tablevie form

-(NSInteger)getTextFieldCellRow:(id)element{
    UITableViewCell *cell = (UITableViewCell *)[[(UITextField*)element superview] superview];
    UITableView *table = (UITableView *)[cell superview];
    NSIndexPath *textFieldIndexPath = [table indexPathForCell:cell];
    return textFieldIndexPath.row;

}

Solution

  • Ok, I solved

    -(NSIndexPath *) getButtonCellRow:(UITextField *) b {
        UITableView *tv = nil;
        UIView *superViewTemp = [b superview];
        UITableViewCell *cell=nil;
    
        BOOL isFoundTable=FALSE;
        BOOL isFoundCell=FALSE;
    
        while(superViewTemp != nil && ![superViewTemp isKindOfClass:[UIWindow class]]){
    
            if ([superViewTemp isKindOfClass:[UITableViewCell class]]) {
                cell=(UITableViewCell*)superViewTemp;
                isFoundCell = TRUE;
    
            }else if ([superViewTemp isKindOfClass:[UITableView class]]){
                tv = (UITableView*)superViewTemp;
                isFoundTable = TRUE;
            }
    
            superViewTemp = [superViewTemp superview];
    
            if(isFoundCell && isFoundTable){
                break;
            }
        }
    
        if(tv != nil && cell != nil){
    
            return [tv indexPathForCell:(UITableViewCell*)cell];
        }
        return nil;
    }