开发者

Simple Objective C Question: How can I get access to a variable from other class?

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜