我試圖用另一塊用stringByReplacingOccurrencesOfString一個字符串,但由於某種原因,它給我這個錯誤:的NSString stringByReplacingOccurrencesOfString失敗
-[__NSCFNumber length]: unrecognized selector sent to instance 0x6e49ef0 2012-05-14 16:30:49.741 coop[78129:f803] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFNumber length]: unrecognized selector sent to instance 0x6e49ef0'
NSString *_currentGroup;
NSString *location = [current objectForKey:@"location"];
if(_currentGroup != nil)
{
NSLog(@"_currentGroup: %@", _currentGroup);
// OUTPUT: _currentGroup: 92
location = [location stringByReplacingOccurrencesOfString:@"%group_id%" withString:_currentGroup];
}
當我嘗試以下方法很好用
location = [location stringByReplacingOccurrencesOfString:@"%group_id%" withString:@"anyOtherString"];
我還錯過了什麼嗎?
does NSLog(@「_ currentGroup:%@」,_currentGroup); 實際上給出OUTPUT:_currentGroup:92 –
Jup,這是我從它得到的輸出。 –
你不要初始化_currentGroup – giorashc