【问题标题】:How to Store textField value in nextViewController String如何在 nextViewController 字符串中存储 textField 值
【发布时间】:2014-09-11 05:43:08
【问题描述】:

我有文本字段,我想将此值存储在 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 我想这样做它是如何添加文本字段的,请帮助我。

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

【问题讨论】:

  • 你必须使用委托方法,否则你必须在另一个视图控制器上创建属性。

标签: ios objective-c iphone ios7 nsstring


【解决方案1】:

在主视图控制器中创建一个属性

@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

【讨论】:

  • 我想发送文本字段输入的值
  • 我已经根据你更新了我的答案...请把你的 textField 传递给那里...
  • 在哪里创建新属性 .. 从中删除只读。对此感到抱歉......删除只读后重试......
  • 以及从 NextViewController 发送到DetailedViewController 的dataString 值。怎么寄?
  • 它将通过此​​代码发送使用,现在您想在DetailedViewController中使用它。我对吗 ?如果我是对的,那么尝试在 NSLog(@"Data Print %@",self.dataString); 中的DetailedViewController 中使用dataString;试试这个,您将在DetailedViewController 中获得价值,并且可以在DetailedViewController 中使用此类型的任何地方使用self.dataString ...
【解决方案2】:

如下创建一个名为 scanCode 的属性

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

希望对你有帮助..

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-08-13
    • 1970-01-01
    • 1970-01-01
    • 2019-10-13
    • 2011-09-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多