Pass a method from my custom cells class to the main class

前端 未结 6 1732
余生分开走
余生分开走 2020-12-22 06:04

I have a custom cell. In it is a UITextField linked to customCell.m. I\'m trying to pass the text from the textField to mainVC.m

6条回答
  •  醉话见心
    2020-12-22 06:46

    As per my understanding I think you looking for this approach, Let me know if I am wrong here.

    In did select row at index path, First you need to find the your custom cell and then the textfield you required. Like this:

        - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
        [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
        customCell* cell=(customCell*)[tableView cellForRowAtIndexPath:indexPath.Row];
        NSString* yourTextFieldText=cell.textField.text;
        mainVC* objmainVC=[mainVC alloc]init];
        objmainVC.yourTextFieldText=yourTextFieldText;
        [self.navigationController pushViewController:objmainVC animated:YES];
    
    }
    

    Now you can use yourTextFieldText to mainVC controller as well.

提交回复
热议问题