How to pass NSURL object from one viewcontroller to another viewcontroller

Deepak Thakur

I have an NSURL object in ScanViewController class and pass it to the ListViewController class.

NSURL *url = [NSURL URLWithString:@"http:// some url"];

I am using xib's in my project and can't find an alternative for

[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**

        }
    }
}];
amb

I assume that you're performing a segue from one VC to another. If so, you can do this in your prepareForSegue:sender: method:

if ([segue.identifier isEqualToString:@"segueToListViewController"]) {
    [(ListViewController *)segue.destinationViewController setURL:[NSURL URLWithString:@"http:// some url"]];
}

You have to declare a property in your destination VC to handle the URL, and you will need an accessor method to set that property.

EDIT

As danypata suggested, if you're not using segues, try the following

ListViewController *listViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"ListViewControllerIdentifier"];
[listViewController setURL:[NSURL URLWithString:@"http:// some url"]];
[self presentViewController:listViewController animated:YES completion:nil];

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Pass one variable from one viewcontroller to another viewcontroller

From Dev

How to pass NSMutableDictionary from one viewController to another View controller?

From Dev

How to segue from one viewcontroller to another

From Dev

Pass UISwitch State from One View Controller to Another ViewController

From Dev

How to pass data from one ViewController to MainViewController without using segue?

From Dev

how to pass CoreLocation values from one VIewController to AppDelegate in iOS?

From Dev

How to pass values from a ViewController to another ViewController using a button with Swift 3.0

From Dev

Passing an managedObjectContext from one ViewController to another ViewController in Swift?

From Dev

Accessing CLLocationManager variable from one viewcontroller to another viewcontroller

From Dev

Accessing CLLocationManager variable from one viewcontroller to another viewcontroller

From Dev

How to move one viewcontroller to another viewcontroller after loading progressbar in ios

From Dev

How to take a photo and pass it to another viewcontroller

From Dev

Calling method from one Viewcontroller inside another

From Dev

Programmatically going from one ViewController to another

From Dev

Triggering a specific action in one viewcontroller from another

From Dev

How to pass data from ViewController to a ViewController in a tab bar iOS?

From Dev

How to modified object of child viewcontroller from parent viewcontroller from in swift

From Dev

How to modified object of child viewcontroller from parent viewcontroller from in swift

From Dev

How to change textView in separate ViewController from button in another ViewController?

From Dev

How to pass data from an API call to the ViewController?

From Dev

How to pass data from viewcontroller to tabbarcontroller to navaigationcontroller?

From Dev

How to pass parameters from appDelegate to ViewController?

From Dev

How to pass data from ViewController in custom UIView

From Dev

error during pass variables one viewController to another controller programatically

From Dev

how to pass object from one fragment to another?

From Dev

How to call function from another ViewController

From Dev

How to call another ViewController from the code?

From Dev

How to fill TableView with data from another ViewController

From Dev

How to call function from another ViewController

Related Related

  1. 1

    Pass one variable from one viewcontroller to another viewcontroller

  2. 2

    How to pass NSMutableDictionary from one viewController to another View controller?

  3. 3

    How to segue from one viewcontroller to another

  4. 4

    Pass UISwitch State from One View Controller to Another ViewController

  5. 5

    How to pass data from one ViewController to MainViewController without using segue?

  6. 6

    how to pass CoreLocation values from one VIewController to AppDelegate in iOS?

  7. 7

    How to pass values from a ViewController to another ViewController using a button with Swift 3.0

  8. 8

    Passing an managedObjectContext from one ViewController to another ViewController in Swift?

  9. 9

    Accessing CLLocationManager variable from one viewcontroller to another viewcontroller

  10. 10

    Accessing CLLocationManager variable from one viewcontroller to another viewcontroller

  11. 11

    How to move one viewcontroller to another viewcontroller after loading progressbar in ios

  12. 12

    How to take a photo and pass it to another viewcontroller

  13. 13

    Calling method from one Viewcontroller inside another

  14. 14

    Programmatically going from one ViewController to another

  15. 15

    Triggering a specific action in one viewcontroller from another

  16. 16

    How to pass data from ViewController to a ViewController in a tab bar iOS?

  17. 17

    How to modified object of child viewcontroller from parent viewcontroller from in swift

  18. 18

    How to modified object of child viewcontroller from parent viewcontroller from in swift

  19. 19

    How to change textView in separate ViewController from button in another ViewController?

  20. 20

    How to pass data from an API call to the ViewController?

  21. 21

    How to pass data from viewcontroller to tabbarcontroller to navaigationcontroller?

  22. 22

    How to pass parameters from appDelegate to ViewController?

  23. 23

    How to pass data from ViewController in custom UIView

  24. 24

    error during pass variables one viewController to another controller programatically

  25. 25

    how to pass object from one fragment to another?

  26. 26

    How to call function from another ViewController

  27. 27

    How to call another ViewController from the code?

  28. 28

    How to fill TableView with data from another ViewController

  29. 29

    How to call function from another ViewController

HotTag

Archive