• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Regarding MVC design pattern
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Regarding MVC design pattern


  • Subject: Re: Regarding MVC design pattern
  • From: Henry McGilton <email@hidden>
  • Date: Sun, 16 May 2010 22:29:10 -0700

On May 15, 2010, at 10:56 AM, Sai wrote:

> Hi All,
> I am new to cocoa development. Suppose I have an iPhone application follow
> the MVC design pattern.
> The Model is presented by an custom object. And I have declared an instance
> of the Model Object as a IBOutlet
> in my Controller class.

One assumes from your description here that there is a custom object in your XIB document.
And, as you said, your Controller class has an IBOutlet declaration for the Model.

Is there an instance of your Controller class in the XIB document?
Did you connect that Controller's Model IBOutlet to the Model object itself using Interface Builder?

If it's not connected in the XIB document, you need to make the connection, and then the alloc and init
you do as described below is no longer necessary.


> I found that every time I start my application, this
> instance of Model Object will be initialized.
> My first question is who called this init method, what for?

The alloc and init are called when the NIB is loaded.

>
> As I found that it will be initialized automatically, so I just send message
> for that instance, and crashed at runtime
> with a exc_bad_access signal error. So I have to call alloc and init for
> that Model Object and assign the returned
> instance to the IBOutlet variable, then everything runs well.

> My second question is if I have to allocate and initialized that Model
> Object for myself? Is it over-done for this
> initialization because it is called automatically before.

Yes, but if you had made the connection from Controller to Model in the XIB document,
you would not need to alloc and init a new instance.

> My third question is where I should call the release method for this
> instance of Model Object?

You release the Model object when you no longer need it.

    Best Wishes,
        . . . . . . . .    Henry

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Regarding MVC design pattern
      • From: Sai <email@hidden>
References: 
 >Regarding MVC design pattern (From: Sai <email@hidden>)

  • Prev by Date: TIPS : Using Add2Project to organize your projects more effectively.
  • Next by Date: Re: Regarding MVC design pattern
  • Previous by thread: Regarding MVC design pattern
  • Next by thread: Re: Regarding MVC design pattern
  • Index(es):
    • Date
    • Thread