2011-05-03 36 views
0

嗨!我試圖將ViewController中的NSString傳遞給NSObject中的NSString。 這裏是我在我的NSObject中使用的代碼來調用字符串並將其傳遞給我的新字符串。嘗試將ViewController中的字符串傳遞給NSObject中的字符串..但它無法工作

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

的問題是,一旦按下視圖上的按鈕啓動該方法在我的NSObject它工作甜但是沒有被傳遞給tempRegCode ..這是我的日誌。

[會話開始於2011-05-03 9時27分35秒+ 1200] 2011-05-03 09:27:36.264 instaCode1.3 [1456:207]百勝百勝餵我更多的cookie! ! func = ERROR 代碼= 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確定按鈕被按下 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]; 

}

+0

我認爲我們需要去看更多的代碼。 registerdeviceviewcontrollers初始化方法是什麼樣子的? – 2011-05-03 01:17:11

+0

Surly如果將UItextField傳遞給視圖控制器內的NSString(如NSLog所示),我應該可以將該字符串傳遞給NSObject。當你說你想看到init方法時,你是指我接受輸入到我的文本字段的方法? – tinhead 2011-05-03 01:29:03

回答

0

爲了訪問checkString這樣,你需要checkString是一個非原子屬性。

在你RegisterDeviceViewController.h的底部,只是@end之前,加

@property (nonatomic, retain) NSString *checkString; 

然後,在RegisterDeviceViewController.m的頂部,只是@implementation RegisterDeviceViewController後,加

@synthesize checkString;