How to retrieve passed data from another view controller? - Objective-C











up vote
-2
down vote

favorite












SendDataVc.m - Sending data from.



GetDataVC.m - Retrieving the data sent from SendDataVc.m



SendDataVC.m:



NSString *theData = @"Sending data";

GetDataVC *passdataVC = [[GetDataVC alloc] init];

passdataVC.theData = theData;


GetDataVC.h:



@property (strong, nonatomic) NSString *theData;


GetDataVC.m:



-(void) getData
{
NSLog( @"%@", _theData);
}


I tried doing this way but I got null instead.










share|improve this question









New contributor




sha he ra is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • That seems correct. Now the questions is where is called getData? Do you use Storyboard & Segue? How is presented passdataVC? Do you do a present? a Push?
    – Larme
    Nov 7 at 9:10















up vote
-2
down vote

favorite












SendDataVc.m - Sending data from.



GetDataVC.m - Retrieving the data sent from SendDataVc.m



SendDataVC.m:



NSString *theData = @"Sending data";

GetDataVC *passdataVC = [[GetDataVC alloc] init];

passdataVC.theData = theData;


GetDataVC.h:



@property (strong, nonatomic) NSString *theData;


GetDataVC.m:



-(void) getData
{
NSLog( @"%@", _theData);
}


I tried doing this way but I got null instead.










share|improve this question









New contributor




sha he ra is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • That seems correct. Now the questions is where is called getData? Do you use Storyboard & Segue? How is presented passdataVC? Do you do a present? a Push?
    – Larme
    Nov 7 at 9:10













up vote
-2
down vote

favorite









up vote
-2
down vote

favorite











SendDataVc.m - Sending data from.



GetDataVC.m - Retrieving the data sent from SendDataVc.m



SendDataVC.m:



NSString *theData = @"Sending data";

GetDataVC *passdataVC = [[GetDataVC alloc] init];

passdataVC.theData = theData;


GetDataVC.h:



@property (strong, nonatomic) NSString *theData;


GetDataVC.m:



-(void) getData
{
NSLog( @"%@", _theData);
}


I tried doing this way but I got null instead.










share|improve this question









New contributor




sha he ra is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











SendDataVc.m - Sending data from.



GetDataVC.m - Retrieving the data sent from SendDataVc.m



SendDataVC.m:



NSString *theData = @"Sending data";

GetDataVC *passdataVC = [[GetDataVC alloc] init];

passdataVC.theData = theData;


GetDataVC.h:



@property (strong, nonatomic) NSString *theData;


GetDataVC.m:



-(void) getData
{
NSLog( @"%@", _theData);
}


I tried doing this way but I got null instead.







objective-c xcode






share|improve this question









New contributor




sha he ra is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




sha he ra is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited Nov 7 at 9:33









Cœur

16.8k9101139




16.8k9101139






New contributor




sha he ra is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked Nov 7 at 7:56









sha he ra

1




1




New contributor




sha he ra is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





sha he ra is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






sha he ra is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












  • That seems correct. Now the questions is where is called getData? Do you use Storyboard & Segue? How is presented passdataVC? Do you do a present? a Push?
    – Larme
    Nov 7 at 9:10


















  • That seems correct. Now the questions is where is called getData? Do you use Storyboard & Segue? How is presented passdataVC? Do you do a present? a Push?
    – Larme
    Nov 7 at 9:10
















That seems correct. Now the questions is where is called getData? Do you use Storyboard & Segue? How is presented passdataVC? Do you do a present? a Push?
– Larme
Nov 7 at 9:10




That seems correct. Now the questions is where is called getData? Do you use Storyboard & Segue? How is presented passdataVC? Do you do a present? a Push?
– Larme
Nov 7 at 9:10












4 Answers
4






active

oldest

votes

















up vote
0
down vote













I think the application doesn't running to the function - (void) getData, you should call this function at - (void)viewDidLoad or - (void)viewWillAppear or something else like below:



- (void)viewDidLoad {
[super viewDidLoad];
[self getData];
}
-(void)getData {
NSLog(@"%@", _theData);
}





share|improve this answer






























    up vote
    -1
    down vote













    You can't instantiate a UIViewController that way.



    Use the following approach, in which @"GetDataVC" is the identifier of the view controller you are going to instantiate:



    GetDataVC *passdataVC = (GetDataVC*)[self.storyboard instantiateViewControllerWithIdentifier:@"GetDataVC"];
    passdataVC.theData = theData;





    share|improve this answer





















    • Yes you can. You are assuming that the GetDataVC is in a Storyboard. But you can do all by code.
      – Larme
      Nov 7 at 9:10










    • As stated in Apple document, init isn't a designated initializer for UIViewController. Actually, you can use initWithNibName:bundle: but not init.
      – RyanB
      Nov 7 at 9:30










    • I don't see an issue with that. initWithNibName:bundle: is usefull when using a Xib (with IBOutlets, etc.), but you should be able to do all programmatically.
      – Larme
      Nov 7 at 9:34










    • Ok, you're right. Now, we have to wait for more detail from OP.
      – RyanB
      Nov 7 at 9:50


















    up vote
    -1
    down vote













    Where you execute the function getData?
    If you execute getData at viewDidLoad or init or somewhere before you set the data.
    You can execute the function through a button.
    I think that will deal the problem.






    share|improve this answer




























      up vote
      -1
      down vote













      Just implement the setter of theData property.



      Paste the code below to your GetDataVC.m.



      - (void)setTheData:(NSString *)theData {
      _theData = theData;
      NSLog(@"theData has set: %@", _theData);
      }


      refrence: Apple Document






      share|improve this answer








      New contributor




      SerKo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.


















        Your Answer






        StackExchange.ifUsing("editor", function () {
        StackExchange.using("externalEditor", function () {
        StackExchange.using("snippets", function () {
        StackExchange.snippets.init();
        });
        });
        }, "code-snippets");

        StackExchange.ready(function() {
        var channelOptions = {
        tags: "".split(" "),
        id: "1"
        };
        initTagRenderer("".split(" "), "".split(" "), channelOptions);

        StackExchange.using("externalEditor", function() {
        // Have to fire editor after snippets, if snippets enabled
        if (StackExchange.settings.snippets.snippetsEnabled) {
        StackExchange.using("snippets", function() {
        createEditor();
        });
        }
        else {
        createEditor();
        }
        });

        function createEditor() {
        StackExchange.prepareEditor({
        heartbeatType: 'answer',
        convertImagesToLinks: true,
        noModals: true,
        showLowRepImageUploadWarning: true,
        reputationToPostImages: 10,
        bindNavPrevention: true,
        postfix: "",
        imageUploader: {
        brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
        contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
        allowUrls: true
        },
        onDemand: true,
        discardSelector: ".discard-answer"
        ,immediatelyShowMarkdownHelp:true
        });


        }
        });






        sha he ra is a new contributor. Be nice, and check out our Code of Conduct.










         

        draft saved


        draft discarded


















        StackExchange.ready(
        function () {
        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53185424%2fhow-to-retrieve-passed-data-from-another-view-controller-objective-c%23new-answer', 'question_page');
        }
        );

        Post as a guest
































        4 Answers
        4






        active

        oldest

        votes








        4 Answers
        4






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes








        up vote
        0
        down vote













        I think the application doesn't running to the function - (void) getData, you should call this function at - (void)viewDidLoad or - (void)viewWillAppear or something else like below:



        - (void)viewDidLoad {
        [super viewDidLoad];
        [self getData];
        }
        -(void)getData {
        NSLog(@"%@", _theData);
        }





        share|improve this answer



























          up vote
          0
          down vote













          I think the application doesn't running to the function - (void) getData, you should call this function at - (void)viewDidLoad or - (void)viewWillAppear or something else like below:



          - (void)viewDidLoad {
          [super viewDidLoad];
          [self getData];
          }
          -(void)getData {
          NSLog(@"%@", _theData);
          }





          share|improve this answer

























            up vote
            0
            down vote










            up vote
            0
            down vote









            I think the application doesn't running to the function - (void) getData, you should call this function at - (void)viewDidLoad or - (void)viewWillAppear or something else like below:



            - (void)viewDidLoad {
            [super viewDidLoad];
            [self getData];
            }
            -(void)getData {
            NSLog(@"%@", _theData);
            }





            share|improve this answer














            I think the application doesn't running to the function - (void) getData, you should call this function at - (void)viewDidLoad or - (void)viewWillAppear or something else like below:



            - (void)viewDidLoad {
            [super viewDidLoad];
            [self getData];
            }
            -(void)getData {
            NSLog(@"%@", _theData);
            }






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Nov 9 at 6:09

























            answered Nov 8 at 10:27









            RateRebriduo

            65




            65
























                up vote
                -1
                down vote













                You can't instantiate a UIViewController that way.



                Use the following approach, in which @"GetDataVC" is the identifier of the view controller you are going to instantiate:



                GetDataVC *passdataVC = (GetDataVC*)[self.storyboard instantiateViewControllerWithIdentifier:@"GetDataVC"];
                passdataVC.theData = theData;





                share|improve this answer





















                • Yes you can. You are assuming that the GetDataVC is in a Storyboard. But you can do all by code.
                  – Larme
                  Nov 7 at 9:10










                • As stated in Apple document, init isn't a designated initializer for UIViewController. Actually, you can use initWithNibName:bundle: but not init.
                  – RyanB
                  Nov 7 at 9:30










                • I don't see an issue with that. initWithNibName:bundle: is usefull when using a Xib (with IBOutlets, etc.), but you should be able to do all programmatically.
                  – Larme
                  Nov 7 at 9:34










                • Ok, you're right. Now, we have to wait for more detail from OP.
                  – RyanB
                  Nov 7 at 9:50















                up vote
                -1
                down vote













                You can't instantiate a UIViewController that way.



                Use the following approach, in which @"GetDataVC" is the identifier of the view controller you are going to instantiate:



                GetDataVC *passdataVC = (GetDataVC*)[self.storyboard instantiateViewControllerWithIdentifier:@"GetDataVC"];
                passdataVC.theData = theData;





                share|improve this answer





















                • Yes you can. You are assuming that the GetDataVC is in a Storyboard. But you can do all by code.
                  – Larme
                  Nov 7 at 9:10










                • As stated in Apple document, init isn't a designated initializer for UIViewController. Actually, you can use initWithNibName:bundle: but not init.
                  – RyanB
                  Nov 7 at 9:30










                • I don't see an issue with that. initWithNibName:bundle: is usefull when using a Xib (with IBOutlets, etc.), but you should be able to do all programmatically.
                  – Larme
                  Nov 7 at 9:34










                • Ok, you're right. Now, we have to wait for more detail from OP.
                  – RyanB
                  Nov 7 at 9:50













                up vote
                -1
                down vote










                up vote
                -1
                down vote









                You can't instantiate a UIViewController that way.



                Use the following approach, in which @"GetDataVC" is the identifier of the view controller you are going to instantiate:



                GetDataVC *passdataVC = (GetDataVC*)[self.storyboard instantiateViewControllerWithIdentifier:@"GetDataVC"];
                passdataVC.theData = theData;





                share|improve this answer












                You can't instantiate a UIViewController that way.



                Use the following approach, in which @"GetDataVC" is the identifier of the view controller you are going to instantiate:



                GetDataVC *passdataVC = (GetDataVC*)[self.storyboard instantiateViewControllerWithIdentifier:@"GetDataVC"];
                passdataVC.theData = theData;






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 7 at 8:06









                RyanB

                8481521




                8481521












                • Yes you can. You are assuming that the GetDataVC is in a Storyboard. But you can do all by code.
                  – Larme
                  Nov 7 at 9:10










                • As stated in Apple document, init isn't a designated initializer for UIViewController. Actually, you can use initWithNibName:bundle: but not init.
                  – RyanB
                  Nov 7 at 9:30










                • I don't see an issue with that. initWithNibName:bundle: is usefull when using a Xib (with IBOutlets, etc.), but you should be able to do all programmatically.
                  – Larme
                  Nov 7 at 9:34










                • Ok, you're right. Now, we have to wait for more detail from OP.
                  – RyanB
                  Nov 7 at 9:50


















                • Yes you can. You are assuming that the GetDataVC is in a Storyboard. But you can do all by code.
                  – Larme
                  Nov 7 at 9:10










                • As stated in Apple document, init isn't a designated initializer for UIViewController. Actually, you can use initWithNibName:bundle: but not init.
                  – RyanB
                  Nov 7 at 9:30










                • I don't see an issue with that. initWithNibName:bundle: is usefull when using a Xib (with IBOutlets, etc.), but you should be able to do all programmatically.
                  – Larme
                  Nov 7 at 9:34










                • Ok, you're right. Now, we have to wait for more detail from OP.
                  – RyanB
                  Nov 7 at 9:50
















                Yes you can. You are assuming that the GetDataVC is in a Storyboard. But you can do all by code.
                – Larme
                Nov 7 at 9:10




                Yes you can. You are assuming that the GetDataVC is in a Storyboard. But you can do all by code.
                – Larme
                Nov 7 at 9:10












                As stated in Apple document, init isn't a designated initializer for UIViewController. Actually, you can use initWithNibName:bundle: but not init.
                – RyanB
                Nov 7 at 9:30




                As stated in Apple document, init isn't a designated initializer for UIViewController. Actually, you can use initWithNibName:bundle: but not init.
                – RyanB
                Nov 7 at 9:30












                I don't see an issue with that. initWithNibName:bundle: is usefull when using a Xib (with IBOutlets, etc.), but you should be able to do all programmatically.
                – Larme
                Nov 7 at 9:34




                I don't see an issue with that. initWithNibName:bundle: is usefull when using a Xib (with IBOutlets, etc.), but you should be able to do all programmatically.
                – Larme
                Nov 7 at 9:34












                Ok, you're right. Now, we have to wait for more detail from OP.
                – RyanB
                Nov 7 at 9:50




                Ok, you're right. Now, we have to wait for more detail from OP.
                – RyanB
                Nov 7 at 9:50










                up vote
                -1
                down vote













                Where you execute the function getData?
                If you execute getData at viewDidLoad or init or somewhere before you set the data.
                You can execute the function through a button.
                I think that will deal the problem.






                share|improve this answer

























                  up vote
                  -1
                  down vote













                  Where you execute the function getData?
                  If you execute getData at viewDidLoad or init or somewhere before you set the data.
                  You can execute the function through a button.
                  I think that will deal the problem.






                  share|improve this answer























                    up vote
                    -1
                    down vote










                    up vote
                    -1
                    down vote









                    Where you execute the function getData?
                    If you execute getData at viewDidLoad or init or somewhere before you set the data.
                    You can execute the function through a button.
                    I think that will deal the problem.






                    share|improve this answer












                    Where you execute the function getData?
                    If you execute getData at viewDidLoad or init or somewhere before you set the data.
                    You can execute the function through a button.
                    I think that will deal the problem.







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Nov 7 at 8:18









                    Chenjtc

                    102




                    102






















                        up vote
                        -1
                        down vote













                        Just implement the setter of theData property.



                        Paste the code below to your GetDataVC.m.



                        - (void)setTheData:(NSString *)theData {
                        _theData = theData;
                        NSLog(@"theData has set: %@", _theData);
                        }


                        refrence: Apple Document






                        share|improve this answer








                        New contributor




                        SerKo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                        Check out our Code of Conduct.






















                          up vote
                          -1
                          down vote













                          Just implement the setter of theData property.



                          Paste the code below to your GetDataVC.m.



                          - (void)setTheData:(NSString *)theData {
                          _theData = theData;
                          NSLog(@"theData has set: %@", _theData);
                          }


                          refrence: Apple Document






                          share|improve this answer








                          New contributor




                          SerKo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.




















                            up vote
                            -1
                            down vote










                            up vote
                            -1
                            down vote









                            Just implement the setter of theData property.



                            Paste the code below to your GetDataVC.m.



                            - (void)setTheData:(NSString *)theData {
                            _theData = theData;
                            NSLog(@"theData has set: %@", _theData);
                            }


                            refrence: Apple Document






                            share|improve this answer








                            New contributor




                            SerKo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                            Check out our Code of Conduct.









                            Just implement the setter of theData property.



                            Paste the code below to your GetDataVC.m.



                            - (void)setTheData:(NSString *)theData {
                            _theData = theData;
                            NSLog(@"theData has set: %@", _theData);
                            }


                            refrence: Apple Document







                            share|improve this answer








                            New contributor




                            SerKo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                            Check out our Code of Conduct.









                            share|improve this answer



                            share|improve this answer






                            New contributor




                            SerKo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                            Check out our Code of Conduct.









                            answered Nov 7 at 8:20









                            SerKo

                            1173




                            1173




                            New contributor




                            SerKo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                            Check out our Code of Conduct.





                            New contributor





                            SerKo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                            Check out our Code of Conduct.






                            SerKo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                            Check out our Code of Conduct.






















                                sha he ra is a new contributor. Be nice, and check out our Code of Conduct.










                                 

                                draft saved


                                draft discarded


















                                sha he ra is a new contributor. Be nice, and check out our Code of Conduct.













                                sha he ra is a new contributor. Be nice, and check out our Code of Conduct.












                                sha he ra is a new contributor. Be nice, and check out our Code of Conduct.















                                 


                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function () {
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53185424%2fhow-to-retrieve-passed-data-from-another-view-controller-objective-c%23new-answer', 'question_page');
                                }
                                );

                                Post as a guest




















































































                                這個網誌中的熱門文章

                                Academy of Television Arts & Sciences

                                L'Équipe

                                1995 France bombings