我NSURL在ScanViewController课堂上有一个对象并将它传递给ListViewController类.
NSURL *url = [NSURL URLWithString:@"http:// some url"];
Run Code Online (Sandbox Code Playgroud)
我在我的项目中使用xib,但找不到替代品
[self.storyboard instantiateViewControllerWithIdentifier:]
[NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error)
{
if(error || !data)
{
NSLog(@"JSON NOT posted");
}
else
{
NSLog(@"JSON data posted!");
id jsonObject = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:Nil];
if([jsonObject respondsToSelector:@selector(objectForKey:)])
{
NSDictionary *dictionaryForUserID = [jsonObject valueForKey:@"ProjID"];
NSLog(@" Project Id = %@", dictionaryForUserID);
NSURL *urlToDisplayInListView = [NSURL URLWithString:[NSString stringWithFormat:@"http://some url/%@", dictionaryForUserID]]; **//Pass this object to other viewcontroller**
}
}
}];
Run Code Online (Sandbox Code Playgroud)
我假设你正在从一个VC到另一个VC执行一个segue.如果是这样,您可以在您的prepareForSegue:sender:方法中执行此操作:
if ([segue.identifier isEqualToString:@"segueToListViewController"]) {
[(ListViewController *)segue.destinationViewController setURL:[NSURL URLWithString:@"http:// some url"]];
}
Run Code Online (Sandbox Code Playgroud)
您必须在目标VC中声明属性以处理URL,并且您将需要一个访问器方法来设置该属性.
编辑
正如danypata建议的那样,如果你不使用segues,请尝试以下方法
ListViewController *listViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"ListViewControllerIdentifier"];
[listViewController setURL:[NSURL URLWithString:@"http:// some url"]];
[self presentViewController:listViewController animated:YES completion:nil];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
719 次 |
| 最近记录: |