• 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: calling a function in one class from another
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: calling a function in one class from another


  • Subject: Re: calling a function in one class from another
  • From: Joanna Carter <email@hidden>
  • Date: Thu, 5 Aug 2010 20:13:13 +0100

Hi Geoffrey

> If I have a class 'Foo' (containing the function 'Wabble'), which loads
> another class 'Bar', is it possible a function within 'Bar' to execute the
> 'Wabble' function within the calling class 'Foo'?

Your first problem is that you are talking about classes without thinking about instances of those classes (objects).

Am I to take it that 'Wabble' is the method that creates and shows the view?

What you also need to consider is how you are going to get the address book data into the editing view. The easier way is to connect the controls on the form to properties of an object, using the bindings mechanism provided by Cocoa.

You need something like this:

@interface DataClass : NSObject
{
  // fields to hold data
}

@property NSString *name;

@property NSString *addressLine1;

…

- (void) showView;

@end

@implementation

- (void) showView
{
  DataViewController *controller = [[DataViewController alloc] initWithData:self];

  ...
}

@end


@interface DataViewController : NSObject
{
  @private
    DataClass *dataProvider;
}

- (DataViewController *) initWithData:(DataClass *)data;

…

@end

@implementation DataViewController

- (DataViewController *) initWithData:(DataClass *)data
{
  self = [super init…];

  if (self)
  {
    dataProvider = data;
  }

  return self;
}

@end

Then you can bind the controls from the view to the properties of the DataClass instance that are available on the dataProvider field in the DataViewController class.

Joanna

--
Joanna Carter
Carter Consulting

_______________________________________________

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

References: 
 >calling a function in one class from another (From: Geoffrey Holden <email@hidden>)

  • Prev by Date: Re: Resolution of an NSImage(Rep)?
  • Next by Date: Re: Resolution of an NSImage(Rep)?
  • Previous by thread: Re: calling a function in one class from another
  • Next by thread: AttributedString from NSData on iPhone.
  • Index(es):
    • Date
    • Thread