tags:

views:

26

answers:

1

It is my MyName.h:

#import <Foundation/Foundation.h>


@interface MyName : NSObject {
    NSString *myName;

}

@property(readwrite) NSString *myName;


@end

and this is the .m:

#import "MyName.h"


@implementation MyName

@synthesize myName;

@end

It is my another controller.m

#import "MyName.h"
#import "MainViewController.h"

@implementation MainViewController

- (void)viewDidLoad {
    self.myName = @"My Name is Peter";
}

......


@end

And I get the Request for member "myName" in something may a structure or union error. wt's happen?

A: 

If you're declaring "myName" as a member of the MyName class, you need to instantiate a MyName object and set your variable there. Right now you're trying to set it on MainViewController.

Nick Stamas
can u give me some example, I still don't understand.
Tattat
It sounds like you may not be familiar with object oriented programming. You need to understand how classes/objects work to get much done in Obj-C. I can point you at some resources if you'd like.
Nick Stamas
I get ur point, well, do I need to make a init method for "MyName"? But actually, I just want something can be a middle man for me to pass two view between different controller.
Tattat