0

嗨,我试图将 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 feed me more cookie!! func=ERROR Code=1 Text=请注册设备 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=(空)

正如你在最后看到的那样 '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];

}

4

1 回答 1

0

Do you set the property checkString to anything in the -init method of your view controller? If you don't, it will default to NULL.

Something like this (in your RegisterDeviceViewController.m file):

- (id)init {
    self.tempRegCode = @"My String";
}

If you are trying to get a string that is in an already-instanciated copy of RegisterDeviceViewController, you need a reference to that copy, not to a newly allocated one. For example, if you have an instance of RegisterDeviceViewController in your XIB file, use an IBOutlet to this instance in your NSObject subclass then call -tempRegCode on that instance.

于 2011-05-02T21:53:14.600 回答