我有文本字段,我想将此值存储在nextViewController中的字符串中,并使用url发送该字符串。怎么可能?
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];
}
我要在NextViewController中执行此操作,它如何添加textField请帮助我。
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");
}
最佳答案
在主视图控制器中创建一个属性
@interface DigiPhotoTableViewController : UIViewController
@property (nonatomic, strong) NSString* dataString;
@end
并使用mainViewcontroller对象从其他视图控制器发送值,例如第一个Import DigiPhotoTableViewController
使用主类对象并发送值后
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];
}
有关更多详细信息,请访问此链接Pass a value from one ViewController to another ViewController
关于ios - 如何在nextViewController字符串中存储textField值,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/25779879/