Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/44.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 如何从文本字段获取更改文本_Iphone_Sdk - Fatal编程技术网

Iphone 如何从文本字段获取更改文本

Iphone 如何从文本字段获取更改文本,iphone,sdk,Iphone,Sdk,我有带有自定义单元格的tableview。该单元格有2个文本字段。我需要从viewcontroller中找到该文本字段中更改的文本 如果我使用 * (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string 此方法不适用于从mainviewcontroller调用 所以我发送的通知是这样的 [[NSNotifi

我有带有自定义单元格的tableview。该单元格有2个文本字段。我需要从viewcontroller中找到该文本字段中更改的文本

如果我使用

* (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
此方法不适用于从mainviewcontroller调用

所以我发送的通知是这样的

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(CalculateAmountInCartList:) name:UITextFieldTextDidChangeNotification object:nil];
在这里,我得到的文本字段文本被更改了。但我无法控制那个文本字段和特定单元格的索引,我也无法得到

请提出建议

谢谢,
Rakesh

您可以使用标记来完成此操作,但不确定这是最佳方式

将标记添加到viewDidLoad方法中的textfield

textField.tag=1//整数。。1、10、99等


(BOOL)textField:(UITextField*)textField应更改字符范围:(NSRange)范围替换字符串:(NSString*)字符串 { 如果(textField.tag==1){ } 如果(textField.tag==2){ }
}您可以使用您知道的NSNotificationCenter发布消息

- (void)postNotificationName:(NSString *)notificationName object:(id)notificationSender userInfo:(NSDictionary *)userInfo

因此,您可以在NSDictionary中粘贴几乎任何您想要的内容。

我建议您尝试确定哪个字段是第一响应者;这里有一个示例代码来解释如何做到这一点

然后,我还会将一个标记关联到每个编辑字段,以便您知道表中的哪一行与编辑字段关联,类似于@KiranThorat所建议的