2010-09-29 83 views
0

我有自定义单元格的tableview。单元格有2个textfields.Fromcontroller我需要找到该文本字段中更改的文本。如何从文本字段获取更改文本

如果我使用

* (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string 

这个方法是不是在呼吁从mainviewcontroller调用。

所以我发送通知,这样

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(CalculateAmountInCartList:) name:UITextFieldTextDidChangeNotification object:nil]; 

在这里,我得到那个textfiled文本changed.But我没有对哪个文本字段和特定的细胞还我没有得到的指标控制。

请给出任何建议。

感谢, 拉克什

回答

0

为此,您可以使用标签,不知道这是最好的方式..

附加标签在viewDidLoad方法以文本框..

textField.tag = 1; //整数数目.. 1,10,99等


(BOOL)的TextField:(的UITextField *)的TextField shouldChangeCharactersInRange:(NSRange)范围replacementString:(的NSString *)串 { 如果(文本框.TAG == 1){} 如果 (textField.tag == 2){} }

0

你被允许张贴使用NSNotificationCenter你知道的消息。

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

所以你可以在NSDictionary中粘贴几乎任何你想要的东西。

0

我建议你尝试确定哪个字段是第一响应者;这里有一个示例代码Get the current first responder without using a private API解释如何做到这一点。

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

相关问题