Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8739725
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:59:39+00:00 2026-06-13T10:59:39+00:00

Today i would ask you if there is a way to call a method

  • 0

Today i would ask you if there is a way to call a method of another view controller just not initializing it or just how to get that viewController as a global variable declared in .h file.
Help me please.
I’m using a PageViewController and I have to use a method of the contentViewController alredy initialized.

here I create my ViewControllers:

- (void)createTheContent {

NSLog(@"createTheContent");
pageController = nil;
//[pageController removeFromParentViewController];
//[pageController awakeFromNib];
NSDictionary *options = [NSDictionary dictionaryWithObject:[NSNumber numberWithInteger:UIPageViewControllerSpineLocationMin] forKey: UIPageViewControllerOptionSpineLocationKey];

self.pageController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStylePageCurl navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options: options];

pageController.dataSource = self;
[[pageController view] setFrame:CGRectMake(0, 0, 320, 365)];

initialViewController = [self viewControllerAtIndex:0];
NSMutableArray *viewControllers = [NSArray arrayWithObject:initialViewController];
[pageController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];

[self addChildViewController:pageController];
[[self view] addSubview:[pageController view]];
[pageController didMoveToParentViewController:self];


}

here are my propertys in .h file:

        contentViewController *initialViewController;
}

//Page View Controller Properties
@property (strong, nonatomic) UIPageViewController *pageController;
@property (strong, nonatomic) NSArray *pageContent;
@property (strong, nonatomic) NSMutableArray *pageStrings;
@property (strong, nonatomic) id dataObject;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T10:59:40+00:00Added an answer on June 13, 2026 at 10:59 am

    From your question title, it seems you are trying to access your controller to get some data back.

    In this case, my suggestion would be creating a “model” (as in Model-View-Controller) in your design, and make that model accessible from everywhere in your app. An easy way to accomplish the latter point is to make the model class a singleton; or you might make it a class with only class-methods to give access to the data. See also this other answer of mine about the same issue for some sample code.

    After reading your edit, I would suggest the following:

    1. add to your contentViewController class a property say it dataSource;

    2. dataSource is of type contentViewControllerDataSource and provides the method to access all required data, e.g.:

      @protocol contentViewControllerDataSource <NSObject>
        -(NSString*)textViewContent;
      @end
      
    3. before adding contentViewController to the page controller, set its dataSource property:

      initialViewController = [self viewControllerAtIndex:0];
      initialViewController.dataSource = self;
      NSMutableArray *viewControllers = [NSArray arrayWithObject:initialViewController];
      [pageController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];
      
    4. let your self controller implement the contentViewControllerDataSource protocol:

      @interface DonKnowTheNameOfThisOne : UIViewController <contentViewControllerDataSource>
      
      ....
      
      @implementation DonKnowTheNameOfThisOne;
      
      ...
      - (NSString*)textViewContent {
         return value;
      }
      
    5. from contentViewController you will be able to call:

      NSString* textViewContent = self.dataSource.textViewContent;
      

      or:

      self.dataSource.textViewContent = @"NEWVAL";
      

    Hope this helps.

    EDIT:

    After looking at your files:

    Please, remove the #import "ViewController.h" directive at the beginning of contentViewController.h. That should fix the problem you had.

    Another thing: I wrote at point 1 that contentViewController have the property dataSource; ViewController implements the contentViewControllerDataSource protocol and hosts the data that contentViewController would like to access. One class is the “client” of the data; the other “shares” the data through the delegate protocol that you can modify from outside. In your code both the dataSource and the protocol are assigned to the same ViewController class and this makes no sense. So, you can try an fix it: I am not sure now which class should be doing what, but you will know, I hope.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Thought I would ask the knowledgeable StackOverflow community a question that was on my
I'm wondering if there's an easy way (like using strtotime) whereby I can get
My boss would like to find a way for a running executable to ask
maybe my google-fu is just letting me down today, but i have not been
I just came across something that I have not seen before and I thought
As today's MVC3 released, I would like to ask if anyone had experienced problems
today i would ask you if someone know how Check if the user has
Today I would like to ask what does the => SomeType mean. I found
Today, I'm building a little form generator for my firm. It would ask for
I came across an issue today, that my PHP script would send a server

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.