0

Hey guys, I'm trying to add a textfield.text entry to an array. I want to pull the textfield.text from a text field in another view. Here's my code.

- (void)addBookmark{

MultiViewViewController *mainView = [[MultiViewViewController alloc] init];
if (mainView.addressTextField.text.length>1) {

NSString *addedString = [[NSString alloc] initWithFormat:@"%@", mainView.addressTextField.text];
[bookmarksArray addObject:addedString];
NSLog(@"addBookmark being called %@", mainView.addressTextField.text);
}
[bmTableView reloadData];

}

The NSLog says the mainView.addressTextField.text is (NULL). What am I doing wrong?

0

4 Answers 4

2

The problem I think is you want the text written in the textfield of a view controller which is existing in your view hierarchy, so you should get the reference of that view controller.

But in the case of yours you are not getting the reference of an existing object, rather you are making a new object

MultiViewViewController *mainView = [[MultiViewViewController alloc] init];

which is not the instance which has text in its textfield.

Hope this helps.

Thanks,

Madhup

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

Comments

0

I would have to see the - (id)init method, but at first sight, it looks like addressTextField is a nil ivar, thus your nslog is correct.

Comments

0

How did you generate the text field? Was it generated programmatically, or with a xib file? If it was in a xib file, you should call initWithNibName:bundle:

1 Comment

The text field was generated using a nib. I'm at a loss for how to get the current text in a text field from another view. Could someone please post some sample code for how to do this in it's basic form? or a link of where I should be headed. Thanks.
0

The text property of an UITextField in nil by default. So if there is no text in it, it should actually be nil.

Documentation

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.