It is my MyName.h:
#开发者_JAVA技巧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?
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.
精彩评论