Search code examples
iosobjective-ciphoneios7nsstring

How to Store textField value in nextViewController String


i have text field and i want to store this value in string in nextViewController and the string sending with url. how it is possible?

if ([textField.text length]== 0) {
    [[[UIAlertView alloc] initWithTitle:@"DigiPhoto" message:@"Please Enter The Code" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil] show];
} else {

    DigiPhotoTableViewController * photoView = [[DigiPhotoTableViewController alloc]init];
    [self.navigationController pushViewController:photoView animated:YES];

}

In NextViewController i want to do This how it added the textField please help me.

scanCode = textField.text;
NSString * urlString=[NSString stringWithFormat:@"url %@",scanCode];

NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:[urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]];

// Create url connection and fire request
NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:request delegate:self];

if (!conn)
{
    responseData = nil;
    NSLog(@"Connection Error");
}

Solution

  • Create one property in Main view Controller

    @interface DigiPhotoTableViewController : UIViewController
    @property (nonatomic, strong) NSString* dataString;
    @end
    

    and send value from other view controller using mainViewcontroller object like this first Import DigiPhotoTableViewController

    after use main class object and send value

    if ([textField.text length]== 0) {
        [[[UIAlertView alloc] initWithTitle:@"DigiPhoto" message:@"Please Enter The Code" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil] show];
    } else {
    
        DigiPhotoTableViewController * photoView = [[DigiPhotoTableViewController alloc]init];
        photoView.dataString = textField.text;;
        [self.navigationController pushViewController:photoView animated:YES];
    
    }
    

    For more details visit this link Pass a value from one ViewController to another ViewController