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?
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
which is not the instance which has text in its textfield.
Hope this helps.
Thanks,
Madhup