0

In Notes.h :

#import <Foundation/Foundation.h>

@interface Notes : NSObject

@property(nonatomic, copy) NSString *Title;
@property(nonatomic, copy) NSString *Text;
@property(nonatomic, copy) NSString *Date;

-(void)setTitle:(NSString *)Title andText:(NSString *)Text andDate:(NSString *)Date;

@end

in Notes.m :

#import "Notes.h"

@implementation Notes

@synthesize Title = _Title;
@synthesize Text = _Text;
@synthesize Date = _Date;

-(NSString *)description {
    return [NSString stringWithFormat:@"Title: %@ Text: %@ Date: %@", self.Title,     self.Text, self.Date];
}


-(void)setTitle:(NSString *)Title andText:(NSString *)Text andDate:(NSString *)Date{

    self.Title = Title;
    self.Text = Text;
    self.Date = Date;

}

I have two View controllers:

in SecondViewController in a button I have:

Notes *newNote = [[Notes alloc]init];
[newNote setTitle:self.navigationItem.title andText:noteField.text andDate:dateLabel.text];

Which works fine to set the values but how do i "get" these values in FirstViewController?

jscs
  • 63,694
  • 13
  • 151
  • 195
user3001526
  • 81
  • 2
  • 12
  • 1
    Just an FYI, in recent versions of Objective-C, the `@synthesize Title = _Title;` and such synthesize lines are already done implicitly by the compiler if not explicitly overridden (it defaults to the style you're already using). – Kitsune Nov 17 '13 at 22:06
  • Are you using Storyboards? – Peter Foti Nov 17 '13 at 23:16

1 Answers1

0

In ViewController2.h, create the properties to hold the data you will pass:

@property(nonatomic, copy) NSString *Title2;
@property(nonatomic, copy) NSString *Text2;
@property(nonatomic, copy) NSString *Date2;

When you push the new view controller, pass the data when instantializing:

Notes.m

-(void)methodThatPushesTheNewController{

    ViewController2 *vc2 = [self.storyboard instantiateViewControllerWithIdentifier:@"secondViewController"];
    vc2.Title2 = self.Title;
    vc2.Date2 = self.Date;
    [self.navigationController pushViewController:vc2 animated:YES];
}

Note: Be sure to import viewController2.h in Notes.m!

Josue Espinosa
  • 5,009
  • 16
  • 47
  • 81