试图将ViewController中的字符串传递给NSObject中的字符串..但它不起作用

时间:2011-05-03 00:37:56

标签: nsstring uitextfield viewcontroller nsobject

您好我试图将ViewController中的NSString传递给NSObject中的NSString。 这是我在NSObject中使用的代码,用于调用字符串并将其传递给我的新字符串。

    RegisterDeviceViewController *S = [[RegisterDeviceViewController alloc] init];
tempRegCode = S.checkString;
NSLog(@"tempRegCode=%@",tempRegCode);

问题是,一旦在我的NSObject中启动方法的视图上按下按钮,它就可以运行,但是没有任何内容传递给tempRegCode ..这是我的日志。

  

[会议开始于2011-05-03 09:27:35 +1200。]   2011-05-03 09:27:36.264 instaCode1.3 [1456:207] yum yum给我更多的饼干! FUNC = ERROR   码= 1   文字=请注册设备   2011-05-03 09:27:36.266 instaCode1.3 [1456:207] cookieCode = code1   2011-05-03 09:27:37.983 instaCode1.3 [1456:207] alerts.m按下OK按钮   2011-05-03 09:27:49.539 instaCode1.3 [1456:207]用户注册是'22222-22222-22222-22222'   2011-05-03 09:27:49.540 instaCode1.3 [1456:207] tempRegCode =(null)

正如你在最后看到的那样'tempRegCode =(null)??

这就是我将变量传递给checkString

的方法
- (IBAction)submitRegistration:(id)sender{
//NSLog(@"submit Registration button has been pressed");

//add text format here
checkString = regTextField.text;
NSLog(@"Users Registration is '%@'",checkString);

regConnection *Reg= [[regConnection alloc] init];
[Reg startRegConnect];

}

1 个答案:

答案 0 :(得分:0)

为了像这样访问checkString,你需要checkString是一个非原子属性。

在RegisterDeviceViewController.h的底部,就在@end之前,添加

@property (nonatomic, retain) NSString *checkString;

然后,在RegisterDeviceViewController.m的顶部,在@implementation RegisterDeviceViewController之后,添加

@synthesize checkString;