2014-09-11 2 views
0

J'ai le champ de texte et je veux stocker cette valeur dans la chaîne dans nextViewController et la chaîne envoyant avec l'URL. comment c'est possible?Comment stocker la valeur de textField dans la chaîne nextViewController

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]; 

} 

Dans NextViewController je veux faire Cette façon dont il a ajouté le textField s'il vous plaît aidez-moi.

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"); 
} 
+0

vous devez utiliser la méthode des délégués, sinon vous devez créer la propriété sur un autre viewcontroller. –

Répondre

1

Créer une propriété en vue contrôleur principal

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

et envoyer la valeur d'un autre contrôleur de vue en utilisant l'objet mainViewcontroller comme cette première importation DigiPhotoTableViewController

après usage principal objet de classe et d'envoyer la valeur

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]; 

} 

Pour plus de détails visitez ce lien Pass a value from one ViewController to another ViewController

+0

je veux envoyer textfield valeur saisie – Chenna

+0

J'ai mis à jour ma réponse selon vous ... S'il vous plaît passer votre textField là ... –

+0

il montrant erreur comme cette affectation à la propriété readonly – Chenna

0

Créer une propriété nommée SCANCODE comme ci-dessous

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.scanCode=textField.text;//assigning textfield value to scanCodeString 
    [self.navigationController pushViewController:photoView animated:YES]; 

} 

//Next View COntroller..Modify code as below. 

@property(nonatomic,strong) NSString *scanCode; 

//textField.text=scanCode; 
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"); 
} 

espérons qu'il vous aidera ..

+0

aucun champ de texte dans nextViewController. – Chenna

+0

J'ai modifié ma réponse .. laisser un commentaire à cette ligne .. – Vidhyanand

+0

Merci Vidhyanand – Chenna

Questions connexes