-2
我有一個應用程序,當我將一個對象傳遞給方法時,對象的值有時會更改爲null。我在博客中找不到任何這樣的內容,請提出我應該做的事。我覺得這就像通過參考或價值,但知之甚少。對象在被傳入方法後被取消分配
變量聲明在* h文件等
NSNumber* resultSelectedWeekValue;
和屬性
@property (nonatomic, retain) NSNumber* resultSelectedWeekValue;
和implimentaion
@synthesize resultSelectedWeekValue = _resultSelectedWeekValue;
這是委託方法從一個酥料餅獲得的價值
// Show discription of Selected week
-(void) getSelectedWeekDelegateMethod:(NSString*) getSelectedWeek {
_resultSelectedWeekValue = [_dbObject getSelectedWeekValue:getSelectedWeek];
NSLog(@"This is _tempOzs %@ ", _resultSelectedWeekValue);
if ([_productAttributePopover isPopoverVisible]) {
[_productAttributePopover dismissPopoverAnimated:YES];
}
}
NSLog(@"This is _resultSelectedWeekValue %@ and class %@", _resultSelectedWeekValue, [_resultSelectedWeekValue class]); // This say the object is deallocate? this is the code below
if ((_resultSelectedWeekValue != nil) && (_tempGranularProduct != nil || _tempLiquidProduct != nil) && (_tempLbs != nil || _tempOzs != nil)) {
if ([_tempLbs intValue] != 0) {
NSDate* _createdDate = [NSDate date];
//Create the dateformatter object
NSDateFormatter* _formatter = [[[NSDateFormatter alloc] init] autorelease];
//Set the required date format
[_formatter setDateFormat:@"yyyy-MM-dd"];
//Get the string date
NSString* _formatDate = [_formatter stringFromDate:_createdDate];
NSNumber* _getNumBags = [self calculateGranularBags];
NSNumber* _getProductID = [[_dbObject getAppliedProductWeightAttribute:_tempGranularProduct] objectForKey:@"productid"];
NSNumber* _totalInvestment = [[NSNumber alloc] initWithInt:0];
NSLog(@"This is _tempScenarioId %@ and class %@", _tempScenarioId, [_tempScenarioId class]);
NSLog(@"This is _resultSelectedWeekValue %@ and class %@", _resultSelectedWeekValue, [_resultSelectedWeekValue class]);
NSLog(@"This is _getProductID %@ and class %@", _getProductID, [_getProductID class]);
NSLog(@"This is _tempLbs %@ and class %@", _tempLbs, [_tempLbs class]);
NSLog(@"This is _getNumBags %@ and class %@", _getNumBags, [_getNumBags class]);
NSLog(@"This is _totalInvestment %@ and class %@", _totalInvestment, [_totalInvestment class]);
NSLog(@"This is _tempCarryover %@ and class %@", _tempCarryover, [_tempCarryover class]);
NSMutableDictionary* _scenarioProductAttribute = [NSMutableDictionary dictionaryWithObjectsAndKeys:
_tempScenarioId, @"scenarioid",
_resultSelectedWeekValue, @"weekvalue",
_getProductID, @"productid",
_tempLbs, @"lbper1000ft",
_getNumBags, @"numberofbags",
_totalInvestment, @"totalinvestment",
_tempCarryover, @"carry_n",
_formatDate, @"date",
nil];
[_totalInvestment release];
_tempScenarioId = [_dbObject insertScenarioProductAttribute:_scenarioProductAttribute andScenarioId:_tempScenarioId andProductId:_getProductID andSelectedWeekValue:_resultSelectedWeekValue];
// Check Point
[TestFlight passCheckpoint:@"INSERT_GRANULAR_RECORD"];
}
if ([_tempOzs intValue] != 0) {
NSDate* _createdDate = [NSDate date];
//Create the dateformatter object
NSDateFormatter* _formatter = [[[NSDateFormatter alloc] init] autorelease];
//Set the required date format
[_formatter setDateFormat:@"yyyy-MM-dd"];
//Get the string date
NSString* _formatDate = [_formatter stringFromDate:_createdDate];
NSNumber* _getGallons = [self calculateLiquidGallons];
NSNumber* _getProductID = [[_dbObject getAppliedProductWeightAttribute:_tempLiquidProduct] objectForKey:@"productid"];
NSNumber* _totalInvestment = [[NSNumber alloc] initWithInt:0];
NSLog(@"This is _tempScenarioId %@ and class %@", _tempScenarioId, [_tempScenarioId class]);
NSLog(@"This is _resultSelectedWeekValue %@ and class %@", _resultSelectedWeekValue, [_resultSelectedWeekValue class]); // This say the object is deallocate?
NSLog(@"This is _getProductID %@ and class %@", _getProductID, [_getProductID class]);
NSLog(@"This is _tempOzs %@ and class %@", _tempOzs, [_tempOzs class]);
NSLog(@"This is _getGallons %@ and class %@", _getGallons, [_getGallons class]);
NSLog(@"This is _totalInvestment %@ and class %@", _totalInvestment, [_totalInvestment class]);
NSLog(@"This is _tempCarryover %@ and class %@", _tempCarryover, [_tempCarryover class]);
NSMutableDictionary* _scenarioProductAttribute = [NSMutableDictionary dictionaryWithObjectsAndKeys:
_tempScenarioId, @"scenarioid",
_resultSelectedWeekValue, @"weekvalue",
_getProductID, @"productid",
_tempOzs, @"ounces",
_getGallons, @"gallons",
_totalInvestment, @"totalinvestment",
_tempCarryover, @"carry_n",
_formatDate, @"date",
nil];
[_totalInvestment release];
_tempScenarioId = [_dbObject insertScenarioProductAttribute:_scenarioProductAttribute andScenarioId:_tempScenarioId andProductId:_getProductID andSelectedWeekValue:_resultSelectedWeekValue];
您提供了很多代碼,但它們都不能幫助我們解決您的問題。我們需要知道如何設置_resultSelectedWeekValue。它很可能設置爲自動釋放對象,或者意外釋放。 – Joe 2011-12-21 14:33:06
_gosh _that _code _is _hard _to _read。 _why _are _you _putting _underscores _infront _of _all _your _variable _names? – jrturton 2011-12-21 15:16:36
_he _read _somewhere _that _you _can _do _that _for _all _members _of _a _class _and _taken _it _too _far _I _guess – deanWombourne 2011-12-21 15:55:09