JRoss
JRoss

Reputation: 177

How Can I Access my ViewController's Property Variables From Another Class?

Ok, this is really bugging me and I am sure the solution is simple... I am unable to set my ViewController's property variables from another class (SeverConnect.m), which I have declared and synthesized properly in my ViewController's .h/.m files:

ServerConnect.h:

#import <Foundation/Foundation.h>
#import "ViewController.h"
#import "Contact.h"

@class ViewController;

@interface ServerConnect : NSObject
{
Contact *newContact;
NSString *codeRawContent;
NSMutableArray *contactListCopy;
...  //Other variables declared here, but not shown in order to save space

Inside ServerConnect.m:

- (void)parserDidEndDocument:(NSXMLParser *)parser
{
NSLog(@"parserDidFinish");

newContact = [[Contact alloc] initWithCodeInfo:(NSString *)codeInfo
                                       contactName:(NSString *)completeName 
                                      contactImage:(UIImage *)profileImage
                                    contactWebSite:(NSString *)codeRawContent];
[contactListCopy insertObject:newContact atIndex:0];
[ViewController setContactList:contactListCopy];  //Automatic Reference Counting Error Occurs Here: "No known class method for selector 'setContactList:'"
}

As I mentioned above, I have declared and synthesized the property variable, "contactList", in my ViewController's .h/.m files (with no errors):

@property (nonatomic, retain) NSMutableArray *contactList;  //In ViewController's .h file
@synthesize contactList;  //In ViewController's .m file

Can someone tell me what I am doing wrong? Thanks in advance for any help you can provide!

Upvotes: 1

Views: 1704

Answers (2)

Edwin Iskandar
Edwin Iskandar

Reputation: 4119

you are trying to access an instance property on a class:

[ViewController setContactList:contactListCopy];

you need to first create an instance of the ViewController class, and then set its property. Something like this:

ViewController *viewController = [[ViewController alloc] init];
[viewController setContactList:contactListCopy];

Upvotes: 1

Levi
Levi

Reputation: 7343

In this line of code:

[ViewController setContactList:contactListCopy];

you should be using a variable of type ViewController. The way you are using it, it should be a class method, not a property. Write something like:

ViewController *viewController = [[ViewController alloc] init];

[viewController setContactList:contactListCopy];

Upvotes: 0

Related Questions