我已經搜索並嘗試了關於此主題上堆棧溢出中的單例,公共和全局變量的每個示例。我在某個地方犯了一個錯誤。我有一個名爲strIP的設置變量,它是textField的一部分,並在我的secondViewController.h中聲明。我想讓這個變量在一個名爲myWSupdate.m的類中使用。這只是我想將它傳遞給連接字符串的一個變量。這編譯正確,但應用程序崩潰運行。我做錯了什麼?從編譯單身人士,公共或全局變量使用
錯誤:終止應用程序由於未捕獲的異常 'NSInvalidArgumentException',原因: '+ [SecondViewController sharedIP]:無法識別的選擇發送到類0x6403c'
secondViewController.h
@interface SecondViewController : UIViewController
{
UITextField *ipAdd;
NSString *strIP;
}
@property (nonatomic, retain) IBOutlet UITextField *ipAdd;
@property (retain) NSString *strIP;
+(SecondViewController*)sharedIP;
然後我叫它myWSupdate.m:
#import "SecondViewController.h"
/* Implementation of the service */
@implementation myWSupdate
- (id) init
{
if(self = [super init])
{
SecondViewController* IP = [[SecondViewController sharedIP]init];
NSLog(@"the test has %@", IP.strIP);
}
}
@end
問題是什麼? – Odys 2012-04-02 19:54:17
我在myWSupdate.m中一直收到「使用未聲明的標識符」strIP'的錯誤。「我錯過了什麼? – iDev 2012-04-02 20:06:50
因爲strIP是SecondViewController的成員,並且您正嘗試使用myWSupdate的方法訪問它? – Almo 2012-04-02 20:09:24