ecnepsnai
ecnepsnai

Reputation: 2026

Pass information between classes

I'm fairly new to Objective-C and I'm running into a problem.

I need to pass some information from one viewcontroller to another. I've tried a number of methods and either get build error or don't make enough sense.

Here is what I have so far.

In the second view controllers h file:

@property (nonatomic) NSString *OwnerID;

The data should go into this property.

In the first view controllers m file:

MoreByUserViewController *moreimg =[[MoreByUserViewController alloc] init];
moreimg.OwnerID = ImageOener;

I think this isn't correct but don't know what else to write.

The clang error I get:

duplicate symbol _m_PageCounter in:
/Users/ianspence/Library/Developer/Xcode/DerivedData/Pickr-dohtanjxfozprjbuwlphjbhvxttm/Build/Intermediates/Pickr.build/Debug-iphonesimulator/Pickr.build/Objects-normal/i386/PKRViewController.o
/Users/ianspence/Library/Developer/Xcode/DerivedData/Pickr-dohtanjxfozprjbuwlphjbhvxttm/Build/Intermediates/Pickr.build/Debug-iphonesimulator/Pickr.build/Objects-normal/i386/MoreByUserViewController.o
ld: 1 duplicate symbol for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Upvotes: 0

Views: 194

Answers (3)

Guru
Guru

Reputation: 22042

Your problem is something else, now you are getting error for _m_PageCounter. I think twice you put m_PageCounter or used same variable in two different headers..

in .h file just declare @class MoreByUserViewController. and add header file of MoreByUserViewController in .m fie.

    @interface MoreByUserViewController : UIViewController
    {
        NSString *mOwnerID;
    }
    @property(nonatomic, retain) NSString *OwnerID;
   -(id)initWithID:(NSString*)inId;
    @end

    @implementation MoreByUserViewController

    @synthesize OwnerID = mOwnerID; 

    -(id)initWithID:(NSString*)inId
   {
      if(self = [super init])   
      {
          self.OwnerID = inId;
      }
      return self;
   }

    @end

//Somewhere else in code

MoreByUserViewController *moreimg =[[MoreByUserViewController alloc] initWithID:@"AnyIdOnUrWish"];

Upvotes: 0

benzado
benzado

Reputation: 84328

duplicate symbol _m_PageCounter means you have a constant or variable or function named m_PageCounter defined in two places. Specifically, in PKRViewController.m and MoreByUserViewController.m.

Your options:

  1. Delete one of them.
  2. Rename one of them.
  3. Declare one of them static so they won't be visible outside of that source file.

Upvotes: 0

Dougen
Dougen

Reputation: 41

Is it a circular reference? check out your header files.

Upvotes: 1

Related Questions