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 6350983
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T21:54:55+00:00 2026-05-24T21:54:55+00:00

I am building a utility application which shares data between main view and flip

  • 0

I am building a utility application which shares data between main view and flip view. Actually, it is not exactly the flip view that’s holding data, it’s the custom view that’s an instance of the flip view when it gets loaded. I have explained the specifics in my previous thread here, but I haven’t got a solution yet. And I have redeveloped my code, hopefully this time I could make myself clear.

The general concept here is I create and store data in my main view, and pass it to the flip side view using the predefined delegate in the FlipViewController. Then in the FlipViewController, I store the data in my own delegate and pass it to the custom view which implements my own delegate method. The following is the main portions of the code.

MainViewController.m (only adopts <FlipsideViewControllerDelegate> protocol)

- (IBAction)showInfo:(id)sender {    

    FlipsideViewController *controller = [[FlipsideViewController alloc] initWithNibName:@"FlipsideView" bundle:nil];
    controller.delegate = self;

    controller.chart = data;

    controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
    [self presentModalViewController:controller animated:YES];

    [controller release];
}

FlipsideViewController.h

@protocol FlipsideViewControllerDelegate;
@protocol ChartDelegate;

@interface FlipsideViewController : UIViewController {
    id <FlipsideViewControllerDelegate> delegate;
    id <ChartDelegate> delegate2;
    DataModel *chart;
}

@property (nonatomic, assign) id <FlipsideViewControllerDelegate> delegate;
@property (nonatomic, assign) id <ChartDelegate> delegate2;
@property (nonatomic, retain) DataModel *chart;
- (IBAction)done:(id)sender;
@end


@protocol FlipsideViewControllerDelegate
- (void)flipsideViewControllerDidFinish:(FlipsideViewController *)controller;
@end

@protocol ChartDelegate <NSObject>
- (void)getParams:(DataModel *)dataModel;
@end

FlipsideViewController.m

@synthesize delegate, delegate2;
@synthesize chart;

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor viewFlipsideBackgroundColor]; 
        if ([delegate2 respondsToSelector:@selector(getParams:)]) {
        [delegate2 getParams:chart];
    }
}

customDrawing.h

@interface customDrawing : UIView <ChartDelegate>{
    DataModel *chartData;
}
@property (nonatomic, retain) DataModel *chartData;
@end

customDrawing.m

@synthesize chartData;
-(void)getParams:(DataModel *)dataModel{
        chartData = dataModel;
}

It turns out the data didn’t get passed to the chartData object in my custom view. HELP?

  • 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-05-24T21:54:57+00:00Added an answer on May 24, 2026 at 9:54 pm

    You are missing the fundamentals. I do not think you need delegates to achieve this task but here we go.

    A protocol is like a contract. In you FlipsideViewController class you defined the protocol which essentially states if you conform to this protocol then you must implement this method.

    How do you conform to a protocol?

    In MainViewController the @interface will look something like this

    @interface MainViewController : UIViewController <FlipsideViewControllerDelegate>
    

    The fact that you have the protocol written in angled brackets means that you promise to conform to the protocol and therefore have to implement

     - (void)flipsideViewControllerDidFinish:(FlipsideViewController *)controller;
    

    in your MainViewController.m.

    Now when MainNavigationController set’s itself as the delegate (controller.delegate = self;) it finishes the link. This allows the FlipsideViewController to call

    [delegate flipsideViewControllerDidFinish:self];
    

    Which will call the method defined in MainViewController which dismisses the modal view controller.

    You have defined a second protocol (you could have added the method to the first and then you would not have to adopt two protocols) and as others have pointed out you have not linked the classes up by doing

    controller.delegate2 = self;
    

    This would not solve your problem. You would still need to conform to the ChartDelegate by adding it to the declaration. Once you have done that you will still not be out of the water because the method is not correct.

    Full solution – not using delegates as they are not really required here

    MainViewController.h

    @interface MainViewController : UIViewController <FlipsideViewControllerDelegate>
    
    - (IBAction)showInfo:(id)sender;
    
    @end
    

    MainViewController.m

    @implementation MainViewController
    
    - (void)flipsideViewControllerDidFinish:(FlipsideViewController *)controller
    {
        [self dismissModalViewControllerAnimated:YES];
    }
    
    - (IBAction)showInfo:(id)sender
    {    
        FlipsideViewController *controller = [[FlipsideViewController alloc] initWithNibName:@"FlipsideView" bundle:nil];
        controller.delegate = self;
    
        /*
         * The labelText property is defined in the header for FlipsideViewController
         * In this case this is the easiest way to get data from this controller to
         * the controller we are about to display
         */
        controller.labelText = @"WHAT EVER YOU WANT TO SEND"; // <---- sending data
    
        controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
        [self presentModalViewController:controller animated:YES];
    
        [controller release];
    }
    
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
    {
        return (interfaceOrientation == UIInterfaceOrientationPortrait);
    }
    
    @end
    

    FlipsideViewController.h

    @class FlipsideViewController;
    
    @protocol FlipsideViewControllerDelegate
    - (void)flipsideViewControllerDidFinish:(FlipsideViewController *)controller;
    @end
    
    @interface FlipsideViewController : UIViewController
    
    
    /*
     * These properties have been added. The label is used for displaying the text
     * and needs to be hooked up in Interface builder
     *
     * The NSString is the property that is holding the data passed from MainViewController
     */
    @property (nonatomic, retain) IBOutlet UILabel *testLabel;
    @property (nonatomic, copy) NSString *labelText; from MainViewControlller
    
    @property (nonatomic, assign) id <FlipsideViewControllerDelegate> delegate;
    
    - (IBAction)done:(id)sender;
    
    @end
    

    FlipsideViewController.m

    @implementation FlipsideViewController
    
    @synthesize delegate = _delegate;
    
    /*
     * We need to synthesise out properties so we get our getters and setters created
     */
    @synthesize testLabel = _testLabel;
    @synthesize labelText = _labelText;
    
    #pragma mark - View lifecycle
    
    - (void)viewDidLoad
    {
        [super viewDidLoad];
    
        /*
         * This is called once the view is set up and all connections have been made in 
         * interface builder. Therefore we can now set the text of our test label
         */
        self.testLabel.text = labelText;
    }
    
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
    {
        return (interfaceOrientation == UIInterfaceOrientationPortrait);
    }
    
    #pragma mark - Actions
    
    - (IBAction)done:(id)sender
    {
        [self.delegate flipsideViewControllerDidFinish:self];
    }
    
    - (void)dealloc
    {
        /*
         * Memory management for the ivars we added
         */
        [_testLabel release];
        [_labelText release];
        [super dealloc];
    }
    
    @end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm building a utility application that synchronizes files across two systems for Mac OSX.
I'm building an application based on the Utility template from Xcode, to which I
I'm building a C++ application, and I've got several utility objects that all of
I am building a utility page for a web app that I am working
I am building an FTP utility class in C#. In the case that a
I'm building a recording iPad application that will take some moderately large recordings on
I am building an iPhone Utility app that uses UIImageView to display an animation.
I'm building a custom page caching utility that uses a syntax like {Substitution:GetNonCachedData} to
I am building an obscure application which is only available after an involved sign-up
I'm building a small utility method that parses a line (a string) and returns

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.