0

I have this in my table view controller, and i want to pass the cell's text value to my UITextField on the modal view.

- (void)buttonTapped:(id)sender {
    AddName *addName = [[AddName alloc] init];
    UITableViewCell *cell = (UITableViewCell*)[sender superview];
    NSLog(@"text in buttontapped: %@", cell.textLabel.text);
    addName.nameField.text = cell.textLabel.text;
    addName.delegate = self;
    [self presentModalViewController:addName animated:YES];
}

The NSLog shows the correct cell text value.

On my modal view's viewDidLoad method i have this... and the text value never gets set...

- (void)viewDidLoad {
    [super viewDidLoad];
    NSLog(@"text: %@",nameField.text);
    nameField.autocapitalizationType = UITextAutocapitalizationTypeWords;
    nameField.autocorrectionType = UITextAutocorrectionTypeDefault;
    [nameField becomeFirstResponder];
}

What's going on?

Thanks.

1 Answer 1

1

It looks as though you're assuming that the modal view controller has already loaded its view, since I'm assuming nameField is a subview. But clearly at the point that your code is trying to set its text property, the text field and its parent view haven't been loaded yet, so you're sending a -setText: message to nil.

Instead, add a property to your modal view controller of type NSString *, and set that in your buttonTapped implementation. Then, in the modal view controller's -viewWillAppear method, you can take the value from the property and put it into the text field.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.