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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:43:10+00:00 2026-05-24T23:43:10+00:00

I work for a long time with MVC but isn’t assured that correctly I

  • 0

I work for a long time with MVC but isn’t assured that correctly I use this pattern in iOS.

This is my understanding and source code which i use for divisions on model view and controller.

Description:

  1. Model (for example – class MyModel)
    Model this is my data. I use model for defined calculation, data acquisition from the Internet and further I notify the controller on changes in model for example through the NSNotificationCenter.

  2. Controller (for example – class MyController)
    The controller can directly contact the request of its model data, and go directly to the display in view.

  3. View (for example – class MyView)
    View – display and gathering of events from users. View can interaction with controller through target-action and delegate.

Code:

class MyModel:NSObject

    .h ... (some header code)
    .m
    Initialization method...

    // method for get data from internet
    -(NSData *)my_getDataFromInternet:(NSURL *)url{
       NSData *data=[NSData dataWithContentsOfURL:url];
       return data;    
    }

class MyController:UIVIewController

     #import "MyView.h"
     .h
     MyView * my_view;

     #import "MyData.h"
     .m
     Initialization method...
     - (void)init{
        my_view = [[MyView alloc]init];
        my_view.my_target = self;
        self.view = my_view;
     }

     -(void)mycontrolleraction{
        MyData * my_data = ...
        [my_data my_getDataFromInternet:some_url_image];
        my_view.my_image = [UIImage imageWithData:self.my_data];
     }

class MyView:UIView

     .h
     UIImage * my_image;
     property(nonatomic, assign)id my_target;
     .m
     Initialization method...
     - (void)initWithFrame{
         UIButton * my_button = ...
         [button addTarget:my_target ....
         my_image = ...
         [self addSubview:my_image];
         [self addSubview:my_button];
      }

I add target to my button – my_target (my_target – this is my MyController). When user tap in my button – method is executed in the MyController and ask data from my MyData class.

I would like to know where my mistake in using this method in the MVC.

  • 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-24T23:43:11+00:00Added an answer on May 24, 2026 at 11:43 pm

    It looks like you’ve got the right idea. I usually think of the model as something that stores the data as well as operating on it, so it seems a little odd to have the model fetch the image and then just return it without storing it. Having the model hold onto the data would let it avoid having to fetch it again later, but the way you have it isn’t wrong, and where the data comes from is something that should be entirely up to the model.

    One thing I’d suggest, not related to MVC, is to follow the convention for initializers. Your initialization methods must call the superclass’s designated initializer, so your controller’s -init should look like:

    -(id)init
    {
        if ((self = [super init])) {    // double parens to avoid warning about = vs ==
            my_view = [[MyView alloc] init];  // assuming my_view is an ivar
            my_view my_target = self;
        }
        return self;
    }
    

    The same goes for your view and model classes.

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

Sidebar

Related Questions

I've been thinking hard for a long time but couldn't work this out. Consider
I've spent a long time trying to work this out, but no success thus
I've spent a long time trying different things to get this to work but
I've spent a long time building stochastic simulations in Java. They work great, but
Not long time before I've discovered, that new dynamic keyword doesn't work well with
It's been a long time since I did any classic asp work, but was
Probably simple question but it has been a long time since i work with
I'm troubled by this question for a long time now. I work in the
For a long time I tried desperately to get this to work, I've googled,
I have spent hours trying to work this out, and spent a long time

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.