總新手Iphone/Obj。 ç問題:Objective-C阻止NSString被釋放/ dealloc
我有一個名爲Location類,在Location.hi聲明:
@interface Location : NSObject
{
NSString *lat;
NSString *lon;
}
在我Location.mi不得不方法:
-(void)setLatLon:(NSString*)lati:(NSString*)longi
{
NSLog(@"called setLatLon");
lat = lati;
lon = longi;
}
我在位置更新調用從LocationManager中。現在,當我嘗試發送作爲一個JSON與
-(void)sendLocation
{
NSDictionary *sendData = [NSDictionary dictionaryWithObjectsAndKeys:
imei, @"imei",
lat, @"lat",
lon, @"lon",
nil];
...}
我得到這個錯誤:
*** -[CFString retain]: message sent to deallocated instance 0xc05b5d0
所以緯度& LON似乎被釋放。我怎麼能夠阻止這個或者我在這裏實施了一個完全愚蠢的'設計'?
什麼是變量imei?我在你的代碼中沒有看到它。 – user1567896 2012-08-14 12:56:33
在您的字符串對象中使用'retain' .. – Ankur 2012-08-14 12:57:56
您是否閱讀過有關Objective-C存儲管理的任何內容? (並且,如果你是初學者,爲什麼你在非ARC時開始,當ARC將在另一年時間全部出現?) – 2012-08-14 13:02:22