开发者

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

开发者 https://www.devze.com 2022-12-22 10:59 出处:网络
It is my MyName.h: #开发者_JAVA技巧import <Foundation/Foundation.h> @interface MyName : NSObject {

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

精彩评论

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