tags:

views:

40

answers:

3

Hi All,

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

A: 

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){ } }

KiranThorat
A: 

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
A: 

i would suggest you try and determine which field is the first responder; there is example code here http://stackoverflow.com/questions/1823317/how-do-i-legally-get-the-current-first-responder-on-the-screen-on-an-iphone 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

Aaron Saunders