0

I have tableview with custom cells.The cell is having 2 textfields.From viewcontroller i need to find the changed text in that textfield.

if i use

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

this method is not at calling calling from the mainviewcontroller.

So i am sending notification like this

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

here i am getting that textfiled text is changed.But i dont have control on that which text field and index of the particular cell also i am not getting.

Please give any suggestions.

Thanks, Rakesh

vodkhang
  • 18,639
  • 11
  • 76
  • 110
Rakesh
  • 1

3 Answers3

0

You can do this using tag, not sure this is best way..

add tag to textfield in viewDidLoad method..

textField.tag = 1; //Integer number .. 1,10, 99, etc.

in
(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { if (textField.tag == 1) { } if (textField.tag == 2){ } }

k-thorat
  • 4,873
  • 1
  • 27
  • 36
0

You are allowed to post a message using NSNotificationCenter you know.

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

So you could stick pretty much anything you want in a NSDictionary.

willcodejavaforfood
  • 43,223
  • 17
  • 81
  • 111
0

i would suggest you try and determine which field is the first responder; there is example code here Get the current first responder without using a private API explaining how to do that.

then I would also associate a tag to each of the edit fields so you know what row in the table was associated with the edit field, similar to what @KiranThorat suggested

Community
  • 1
  • 1
Aaron Saunders
  • 33,180
  • 5
  • 60
  • 80