-2

i would like to take text from a quiz vc to a category vc so i can upload to parse.com. the user inputs text into a UITextView presses next and goes to the category VC and sends via parse.com

in the quiz.h file

@property (nonatomic,strong) IBOutlet UITextView *textField;
@property (nonatomic, strong) NSString *text;

in quiz.m

    NSString *text = [NSString stringWithFormat:@"%@", [self.textField text]];

IBAction next method{
 categoryViewController *cvc = [[selectFriendsViewController alloc] init];
            cvc.string = text;
            [cvc setString:text];
}

in the category.h

@property (nonatomic, retain)  NSString *string;

selectfriends vc.m

- (void)viewDidLoad {
    [super viewDidLoad];

    quizViewController *qvc = [[quizViewController alloc] init];
    qvc.text = self.string;
    UITextView *textfield = [[UITextView alloc] init];
    self.string = textfield.text;
    [self.textField setText:self.string];
    NSLog(@"%@", self.string);
}

the string does not print and it does not show null + i can not delete anything in the viewdidload as then file then does not upload to parse.com (im uploading text as file). textfile on parse.com is blank. how can i get the string to show and upload to parse?

Harry
  • 17
  • 6
  • possible duplicate of [Passing Data between View Controllers](http://stackoverflow.com/questions/5210535/passing-data-between-view-controllers) – Shamas S Jul 27 '15 at 15:33
  • I'm very new to iOS how can I solve the issue – Harry Jul 27 '15 at 15:36
  • 1
    Divide your problem into smaller chunk. Learn how to get data from a `UITextField`. Learn how to pass that data to next `UIViewController`. Then learn how to populate data to an existing `UITextField` – Shamas S Jul 27 '15 at 15:38
  • any help would be great as i would be able to learn from it. – Harry Jul 27 '15 at 16:29
  • 1
    Don't take it wrong but you should begin with a good tuto first. You may know www.raywenderlich.com, if not, try it. Learn how to create segues, and how to pass values through views. – Jan ATAC Jul 27 '15 at 16:30

3 Answers3

0

What I usually do is create another class, with subclass of NSObject - (I usually call it connector).

In the connector.h file - add as many string properties as needed (ex. a string called 'foo')

Import 'connector' and your second VC into your first VC.

In your secondVC.h file add :

@property(nonatomic,strong) Connector *connector;

and import connector.h

Then in the prepareForSegue method in your first VC add:

Connector *connector = [[Connector alloc]init];
SecondVC *secondVC = [segue.destinationViewController];
connector.foo = string ; (this is your string)
secondVC.connector = connector;

Then all that is left to do is under @implementation in your secondVC.m file you want to synthesize the property.

@synthesize connector;

You should then be able to access the property by doing something like :

NSString *secondVCString = connector.foo;

I am away from my mac - but I think this is correct.

Mike
  • 241
  • 1
  • 13
0

Since you have in your category.h

@property (nonatomic, retain) NSString *string;

you can just override the setter method in the .m file like this:

- (void)setString:(NSString *)string {
    _string = string; //make sure you keep reference to it for future use

    //Send to Parse here
}
AlexKoren
  • 1,605
  • 16
  • 28
0

i took some time to figure this out but then i realised that this was way easier.

first we store the text of the textview in nsuserdefaults and then in the other view controller where you want to get the data we retrieve the data of the nsuserdefaults by using the same key which we used to save data.

hope you like the answer.

Tejas Badani
  • 68
  • 11