0

I have an array. It is filled in one class named "SampleDataDAO".

What i need:

In the 2nd class named "MainMenu" i need to keep this code:

- (void)viewDidLoad
{
[super viewDidLoad];
daoDS = [[SampleDataDAO alloc] init];
self.ds = daoDS.PopulateDataSource;
}

And in the third class named "HView" i need to use array "ds" (NSMutableArray). But i need to use it already filled from 2nd class, to return the count of elements:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return ds.count;
}

Thanks for helping!

1
  • 1
    You can have that array declared and initialised in AppDelegate. Make that array as a property there. Commented Jul 25, 2013 at 11:37

3 Answers 3

5

Why should not you have a singleton class, and have that array as a member of that singleton class.

More info on singleton found here

Sign up to request clarification or add additional context in comments.

Comments

0

Rather than using singletons, or getting a reference to the array from your appDelegate (which is just the same as using a singleton). A better way would be to pass the array as a reference to the view controller when you create it.

This is similar to the way that you pass a managed object context to view controllers if you are using Core Data, rather than calling down to the app delegate to get it.

Comments

-1

Why don't u try to use constant file for this type or requirement.

Use these files for your requirement.

Constant.h
Constant.m

Import Constant.h file in your viewController and use that methods to set and get array directly with class name as

NSArray *array=[Constant getArray];

Or

[Constant setArray:array];

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.