简体   繁体   English

单击按钮保存动态文本字段值

[英]saving dynamic textfield value on click of button

There is CustomCell in tableviewcontroller .And in which there is dynamic txtfield. tableviewcontroller中有CustomCell。其中有动态txtfield。 which is viewed by tag value. 通过标签值查看。 I am saving textfield value on dictionary on "textFieldShouldEndEditing". 我正在“ textFieldShouldEndEditing”上的字典上保存textfield值。 I want to save textfield value on button (Textfied is dynamic,no outlet is created for textfield). 我想在按钮上保存文本字段值(Textfied是动态的,没有为文本字段创建出口)。 First Image attached 附上第一张图片

I want to edit the saved address. 我要编辑保存的地址。 Second Image attached 附加第二张图片

kindly revert asap 尽快回复

If i understood your question properly then, 如果我正确理解了您的问题,

You need to set the button (Which i guess is also inside the custom cell), same tag as that of the indexpath of the cell. 您需要设置按钮(我想也是在自定义单元格内),该按钮与单元格的indexpath相同。 By that you can get the indexPath of the cell and get the cell by MyCustomCell *cell = [self.tableview cellForRowAtIndexPath:button.tag] 这样,您可以获取单元格的indexPath并通过MyCustomCell *cell = [self.tableview cellForRowAtIndexPath:button.tag]获取单元格MyCustomCell *cell = [self.tableview cellForRowAtIndexPath:button.tag]

Then, you can get the textfield inside the cell also by just calling cell.textFieldName.text , and you will get the text. 然后,您也可以通过仅调用cell.textFieldName.text来获取单元格内的文本cell.textFieldName.text ,然后将获取文本。

For more clarity the IBAction method of the button, should be something like this. 为了更加清晰,按钮的IBAction方法应类似于以下内容。

 -(IBAction)buttonClickedToSaveTexd:(id)sender{

      UIButton *btnOfCertainCell = (UIButton*)sender;
      MyCustomCellClass *currentCell = [self.tableView cellForRowAtIndexPath:btnOfCertainCell.tag];
      NSString *textOfTheCell = currentCell.textFieldName.text;
 }

Again, for this to work, in cellForRowAtIndexPath you need to assign the button tag as indexPath.row . 再次,要使其正常工作,在cellForRowAtIndexPath您需要将button标签分配为indexPath.row You dont need to set tag of the textfield. 您不需要设置文本字段的标签。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM