views:

50

answers:

2

My app has a UITextField inside of a table cell. The table cell is build inside of a TableController class which is the table delegate as well. The TableController is a instance variable of a ViewController class.

What I'm trying to do is to send a message to the ViewController instance when the user touches inside the TextField.

This is a code snipped from the TableController:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

        static NSString *CellIdentifier = @"Cell";

        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

        if (cell == nil) {
                 cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease];
        }

        cell.textLabel.text = @"test";

        UITextField *textField = [[[UITextField alloc] initWithFrame:CGRectMake(1.0, 5.0, 120.0, 25.0)] autorelease];
        textField.text = @"test 2";
        [textField addTarget:self action:@selector(editingStarted) forControlEvents:UIControlEventTouchUpInside];    
        cell.accessoryView = textField;
        return cell;

}

The first problem is that the TableControllers method editingStarted gets never called. The next interesting part will be to send a message to the parent ViewController class.

A: 
  1. Set your controller as a delegate of the text field (make sure to adopt the UITextFieldDelegate protocol).
  2. Add the method

.

-(void)textFieldDidBeginEditing:(UITextField *)textField {
    [self editingStarted];
}
KennyTM
Thanks for your fast reply. But I would rather send a direct message without using the delegate.When I'm trying the exact same example with a UISwitch it works.
dan
A: 
natanavra
Thanks for your reply. I will try this. Thanks a lot!
dan