iOS How to pass data from UIViewController to destinationViewController

Artem Z.

I'd like to pass data from MainViewController to specific (It depends on user's choice in GoogleMap) view controller. In MainVC I have NSArray, which is called: userData. The code is:

NSDictionary *tempDictionary = [NSDictionary dictionaryWithObjectsAndKeys:
                                      @"FirstViewController", @"First",
                                      @"SecondViewController", @"Second",
                                      nil];
    NSString *viewControllerIdentifier = [tempDictionary valueForKey:[marker.userData valueForKey:@"controller"]];
    UIViewController *destViewController = [iPhoneStoryboard instantiateViewControllerWithIdentifier:viewControllerIdentifier];
    //destViewController.placeData = marker.userData;
    [self.navigationController pushViewController:destViewController animated:YES];

//destViewController.placeData = marker.userData; doesn't exist. Should I add this NSArray inside UIViewController implementation? Or any ideas? Thank you, Artem :)

KIDdAe

If you are sure that, the viewController instantiate in your storyboard can handle those data, just create your own ViewController Class that manage this NSArray

@interface MyViewController : UIViewController

@property (nonatomic, strong) NSArray placeData;

@end

and in your sample code :

NSDictionary *tempDictionary = [NSDictionary dictionaryWithObjectsAndKeys:
                                  @"FirstViewController", @"First",
                                  @"SecondViewController", @"Second",
                                  nil];
NSString *viewControllerIdentifier = [tempDictionary valueForKey:[marker.userData valueForKey:@"controller"]];
MyViewController *destViewController = (MyViewController *)[iPhoneStoryboard instantiateViewControllerWithIdentifier:viewControllerIdentifier];
destViewController.placeData = marker.userData;
[self.navigationController pushViewController:destViewController animated:YES];

Once this is done, all your viewControllers (assuming there are more than 1) can use this one as mother class

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to pass data from one UIViewController to another one through UITapGestureRecognizer

Pass data from tabBarController to uiviewcontroller embedded in navigationcontroller

Trying to pass data from UICollectionViewCell to UIViewController

How to pass data between a UIViewController and an NSObject in Swift

How to pass selected image from UIImagePicker to the UIViewController

How to pass the device token from AppDelegate to UIViewController

How to pass from one Containerview to Another UIViewController

How to pass an UIImage from UIImagePickerController to another UIViewController?

How to pass a Type of UIViewController to a function and type cast a variable in iOS Swift?

Swift / iOS: How to pass data from AppDelegate to ViewController label?

How to pass model class data from one page another in iOS?

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

How to fill data in UItableview in popover from UIViewcontroller?

How to made a UIViewController class reusable to pass data back to a viewController that calls it

how to pass data in UIPageViewController in ios

How to make the clicks from one UIViewController pass into the parent UIViewController through the hole

Pass NSString from an UIViewController to another

iOS - how to set picker data when I use uiview to uiviewcontroller

Issue passing data to iOS UIViewController

ios Pass data from TabbarController to ViewController in Storyboard

Get Data from UIViewController to Another UIViewController

Sending Cell data to destinationViewController with prepareForSegue

Trying to pass UIButton's tag value when calling UIViewController from .xib file in iOS

iOS switch from a UIView to a UIViewController

ios - Action from UITableView to a UIViewController

How to pass data from BottomSheetFragmentDialog?

how to pass data to previous viewController in iOS swift?

how to change a UILabel of a UIViewController from another UIViewController

How to pass NSString data from my app to iOS native app Notes