Hello i am trying to copy the input from my textfield in the ViewController to my AppDelegate.
No, not vice versa.
As i am trying to do this and i NSLog the gives me this:
StruktonTest[8467:11603] (null)
Btw, StruktonTest is the name of my Testapp.
Here’s my code where i get text in the ViewController:
if ([[[self m_textfield] text] length] == 10) {
m_textfield.text=[NSString stringWithFormat:@"%@", m_textfield.text];
NSLog(@"%@", m_textfield.text);
telefoonnummer = m_textfield.text;
I copy it to my AppDelegate.h file like this:
@interface LocationDelegate : NSObject <CLLocationManagerDelegate>
{
UILabel * resultsLabel;
NSString *phonenumber;
}
- (id) initWithLabel:(UILabel*)label;
-(id)initWithDictionary:(NSDictionary *)dict;
-(id)initWithName:(NSString *)aName;
-(NSDictionary *)toDictionary;
@property (nonatomic , retain) NSString *phonenumber;
And here’s my code from the ViewController, maybe i make the misstake here:
@interface LocationTestViewController : UIViewController <CLLocationManagerDelegate> {
IBOutlet UILabel * m_significantResultsLabel;
IBOutlet UISwitch * m_significantSwitch;
IBOutlet UISwitch * m_mapSwitch;
IBOutlet MKMapView * m_map;
IBOutlet UITextField * m_textfield;
NSString *String;
IBOutlet UILabel * mobielnummer;
IBOutlet UILabel * deellocatie;
IBOutlet UILabel * welldone;
IBOutlet UILabel * locatiemaps;
IBOutlet UILabel * mapslocatie;
NSString *telefoonnummer;
LocationDelegate * m_significantDelegate;
// location objects
CLLocationManager* m_gpsManager;
CLLocationManager* m_significantManager;
}
-(IBAction) actionSignificant:(id)sender;
-(IBAction) actionMap:(id)sender;
-(IBAction) actionLog:(id)sender;
-(IBAction)changrGreeting ;
@property (retain, nonatomic) IBOutlet UILabel * m_significantResultsLabel;
@property (retain, nonatomic) IBOutlet UISwitch * m_significantSwitch;
@property (retain, nonatomic) IBOutlet UISwitch * m_mapSwitch;
@property (retain, nonatomic) IBOutlet MKMapView * m_map;
@property (nonatomic ,retain) IBOutlet UITextField *m_textfield;
@property (nonatomic, copy) IBOutlet NSString *String;
@property (nonatomic, retain) IBOutlet UILabel *mobielnummer;
@property (nonatomic, retain) IBOutlet UILabel *deellocatie;
@property (nonatomic, retain) IBOutlet UILabel *welldone;
@property (nonatomic, retain) IBOutlet UILabel *locatiemaps;
@property (nonatomic, retain) IBOutlet UILabel *mapslocatie;
@property (nonatomic , retain) NSString *telefoonnummer;
@end
And this is the code from my AppDelegate.m
LocationTestViewController*locationTestViewController = [[LocationTestViewController alloc]init];
phonenumber = locationTestViewController.telefoonnummer;
NSLog(@"%@", phonenumber);
So i’m recieving the NULL when i copy this.
Does anybody know how to fix this. Would be appreciated.
This code:
Is creating a new instance of LocationTestViewController, then reading the .telefoonnummer field which is obviously empty.
Surely instead of the AppDelegate ‘reading’ the field, you can use your ViewController to ‘give’ the field to the AppDelegete?
You could use the NSUserDefaults as a temporary store, or use code like this in your ViewController: