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=Please Register Device 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 に答える