开发者

How to set NSString* property from another class?

Please look to the开发者_开发百科 following code.

FirstViewController.h:

@interface FirstViewController : UIViewController {
    NSString* inputData;
}

@property (nonatomic, copy/retain) NSString* inputData;

FirstViewController.m:

@synthesize inputData;

SecondViewController.m:

- (IBAction)buttonSaveDown {
    [firstViewController setInputData:@"Text"];
    firstViewController.inputData = @"Text";
    firstViewController.inputData = [[NSString stringWithString:@"Text"] retain];
}

Add breakpoints after every line with inputData. Check firstViewController.inputData - it's '(null)'! Why?

Printing description of inputData:
(null)

Also I try 'Edit value' in the debugger. After setting value the result is '(null)' too.

There's no any warnings on the build. Please help anybody. Thanks a lot!

To moderators: Sorry, but someone deleted the same previous question when I asked to delete all comments on it.


Your firstViewController variable is not set to anything. You need to set it to a valid instance of FirstViewController before you can do anything useful with it.


Just use

@property (nonatomic, retain) NSString* inputData;

Then these each should work:

[firstViewController setInputData:@"Text"];
firstViewController.inputData = @"Text";
firstViewController.inputData = [NSString stringWithString:@"Text"];
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜