Objective c 对象被释放到';我不知道为什么?
请帮助我,我无法理解为什么会发生这种情况。没有任何原因,对象Objective c 对象被释放到';我不知道为什么?,objective-c,ios,Objective C,Ios,请帮助我,我无法理解为什么会发生这种情况。没有任何原因,对象\u getProductType被释放。请看一看,我不知道发生了什么,如果你能帮助我,我会非常感谢你,提前谢谢 // // ProductComponentViewController.m // TurfNutritionTool // // Created by Aashish Joshi on 10/14/11. // Copyright 2011 Abacus Consul
\u getProductType
被释放。请看一看,我不知道发生了什么,如果你能帮助我,我会非常感谢你,提前谢谢
//
// ProductComponentViewController.m
// TurfNutritionTool
//
// Created by Aashish Joshi on 10/14/11.
// Copyright 2011 Abacus Consultancy Services. All rights reserved.
//
#import "ProductComponentViewController.h"
#import <QuartzCore/QuartzCore.h>
@implementation ProductComponentViewController
@synthesize productTableView = _productTableView;
@synthesize productTypeSelector = _productTypeSelector;
@synthesize turftypePopover = _turftypePopover;
@synthesize gotTurftype = _gotTurftype;
@synthesize resultProduct = _resultProduct;
@synthesize productTableCellStyle = _productTableCellStyle;
@synthesize dbObject = _dbObject;
@synthesize getProductType = _getProductType;
#define Granular @"G"
#define Liquid @"L"
#define Tankmix @"T"
#define AllProduct @"A"
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
// D o any additional setup after loading the view from its nib.
UIColor *_background = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"main_bg.png"]];
self.view.backgroundColor = _background;
[_background release];
// init the segment button value
[productTypeSelector setSelectedSegmentIndex:0];
_getProductType = [[NSString alloc] initWithString:AllProduct];
// set table delegate
_productTableView.delegate = self;
// load the product
[self loadProductComponentValues];
// Set the table view to be rounded
[[_productTableView layer] setCornerRadius:5.0];
}
- (void)viewDidUnload
{
[self setProductTableView:nil];
[self setProductTypeSelector:nil];
_productTableView = nil;
_productTypeSelector = nil;
_turftypePopover = nil;
_gotTurftype = nil;
_resultProduct = nil;
_productTableCellStyle = nil;
_getProductType = nil;
[_getProductType release];
[_productTableView release];
[_productTypeSelector release];
[_turftypePopover release];
[_gotTurftype release];
[_resultProduct release];
[_productTableCellStyle release];
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return YES;
}
- (void)dealloc {
[_getProductType release];
[_productTableView release];
[_productTypeSelector release];
[_turftypePopover release];
[_gotTurftype release];
[_resultProduct release];
[_productTableCellStyle release];
[super dealloc];
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// #warning Potentially incomplete method implementation.
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// #warning Incomplete method implementation.
// Return the number of rows in the section.
// NSLog(@"%s", __FUNCTION__);
return [self.resultProduct count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
[[NSBundle mainBundle] loadNibNamed:@"productContentTableCellStyle" owner:self options:nil];
cell = _productTableCellStyle;
self.productTableCellStyle = nil;
}
NSDictionary * _productRow = [_dbObject getProductdetail:[self.resultProduct objectAtIndex:indexPath.row]];
// Configure the cell...
UILabel* _label = (UILabel *)[cell viewWithTag:1];
NSString* _linkcode = [_productRow objectForKey:@"linkcode"];
_label.text = _linkcode;
_label = (UILabel *)[cell viewWithTag:2];
NSString* _description = [_productRow objectForKey:@"description"];
_label.text = _description;
_label = (UILabel *)[cell viewWithTag:3];
NSString* _productcode = [_productRow objectForKey:@"productcode"];
_label.text = _productcode;
_label = (UILabel *)[cell viewWithTag:4];
NSString* _weight = [_productRow objectForKey:@"weight"];
_label.text = _weight;
_label = (UILabel *)[cell viewWithTag:6];
NSNumber* _costperBag = [[NSNumber alloc] initWithFloat:[[_dbObject getUserProductCost:[self.resultProduct objectAtIndex:indexPath.row]] floatValue]];
_label.text = [@"$ " stringByAppendingString:[_costperBag stringValue]];
[_costperBag autorelease];
_getProductType = [_productRow objectForKey:@"producttype"];
if ([_getProductType isEqualToString:@"G"]) {
_label = (UILabel *)[cell viewWithTag:10];
NSString* _weightTag = [[NSString alloc] initWithString:@"Weight in Lbs"];
_label.text = _weightTag;
[_weightTag autorelease];
_label = (UILabel *)[cell viewWithTag:11];
NSString* _SGNTag = [[NSString alloc] initWithString:@"SGN"];
_label.text = _SGNTag;
[_SGNTag autorelease];
_label = (UILabel *)[cell viewWithTag:5];
NSString* _sgn = [_productRow objectForKey:@"sgn"];
_label.text = _sgn;
} else if([_getProductType isEqualToString:@"L"]) {
_label = (UILabel *)[cell viewWithTag:10];
NSString* _weightTag = [[NSString alloc] initWithString:@"Weight in Ozs"];
_label.text = _weightTag;
[_weightTag autorelease];
_label = (UILabel *)[cell viewWithTag:11];
NSString* _SGTag = [[NSString alloc] initWithString:@"SG"];
_label.text = _SGTag;
[_SGTag autorelease];
_label = (UILabel *)[cell viewWithTag:5];
NSString* _sgn = [_productRow objectForKey:@"sg"];
_label.text = _sgn;
} else if([_getProductType isEqualToString:@"T"]) {
_label = (UILabel *)[cell viewWithTag:10];
NSString* _weightTag = [[NSString alloc] initWithString:@"Weight in Ozs"];
_label.text = _weightTag;
[_weightTag autorelease];
_label = (UILabel *)[cell viewWithTag:11];
NSString* _SGTag = [[NSString alloc] initWithString:@"SG"];
_label.text = _SGTag;
[_SGTag autorelease];
_label = (UILabel *)[cell viewWithTag:5];
NSString* _sgn = [_productRow objectForKey:@"sg "];
_label.text = _sgn;
}
return cell;
}
- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
UIColor *_background = [[[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"toolbar_bkg.png"]] autorelease];
UIView* _customView = [[[UIView alloc]initWithFrame:CGRectMake(10.0, 0.0, 300.0, 44.0)]autorelease];
_customView.backgroundColor = _background;
return _customView;
}
- (UIView *) tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
UIColor *_background = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"toolbar_bkg.png"]];
UIView* _customView = [[[UIView alloc]initWithFrame:CGRectMake(10.0, 0.0, 300.0, 44.0)]autorelease];
_customView.backgroundColor = _background;
[_background release];
return _customView ;
}
#pragma mark - Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// Navigation logic may go here. Create and push another view controller.
/*
<#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil];
// ...
// Pass the selected object to the new view controller.
[self.navigationController pushViewController:detailViewController animated:YES];
[detailViewController release];
if (_delegate != nil) {
NSString *_selectedTurftype = [_getTurftype objectAtIndex:indexPath.row];
[_delegate getSelectedTurftype:_selectedTurftype];
}
*/
// NSDictionary * _productRow = [_dbObject getProductdetail:[self.resultProduct objectAtIndex:indexPath.row]];
// Animate the deselection
[self.productTableView deselectRowAtIndexPath:[self.productTableView indexPathForSelectedRow] animated:YES];
CGRect _popoverRect = CGRectMake(800.0f, 380.0f, 10.0f, 10.0f);
if ([_turftypePopover isPopoverVisible]) {
[_turftypePopover dismissPopoverAnimated:YES];
}
else
{
ProductDetailViewController* _productDetailViewControllerObj = [[ProductDetailViewController alloc] init];
_turftypePopover = [[UIPopoverController alloc]
initWithContentViewController:_productDetailViewControllerObj];
_productDetailViewControllerObj.dbObject = _dbObject;
[_productDetailViewControllerObj getSelectedProductId:[self.resultProduct objectAtIndex:indexPath.row] ];
[_productDetailViewControllerObj release];
_turftypePopover.popoverContentSize = CGSizeMake(360, 500);
[_turftypePopover presentPopoverFromRect:_popoverRect inView:self.view
permittedArrowDirections:0 animated:YES];
}
[self.productTableView deselectRowAtIndexPath:[self.productTableView indexPathForSelectedRow] animated:YES];
}
#pragma mark - ProductComponentViewController lifecycle methods
- (IBAction)laodTurftype:(id)sender {
[self initAllTheProduct];
if (_getProductType == (id)[NSNull null] && _getProductType == nil) {
_getProductType = [NSString stringWithString:AllProduct];
}
if ([_turftypePopover isPopoverVisible]) {
[_turftypePopover dismissPopoverAnimated:YES];
}
else
{
TurftypePopoverViewController* _turftypeControllerObj = [[TurftypePopoverViewController alloc] init];
_turftypeControllerObj.dbObject = _dbObject;
_turftypeControllerObj.delegate = self;
_turftypePopover = [[UIPopoverController alloc]
initWithContentViewController:_turftypeControllerObj];
[_turftypeControllerObj release];
_turftypePopover.popoverContentSize = CGSizeMake(150, 225);
[_turftypePopover presentPopoverFromBarButtonItem:sender
permittedArrowDirections:UIPopoverArrowDirectionAny
animated:YES];
}
}
- (IBAction)setProductType:(id)sender {
switch (_productTypeSelector.selectedSegmentIndex) {
case 0:
_getProductType = [NSString stringWithString:AllProduct];
break;
case 1:
_getProductType = [NSString stringWithString:Granular];
break;
case 2:
_getProductType = [NSString stringWithString:Liquid];
break;
case 3:
_getProductType = [NSString stringWithString:Tankmix];
break;
}
[self loadProductComponentValues];
// Check Point
[TestFlight passCheckpoint:@"SET_PRODUCT_TYPE"];
}
// This is Delgate Method to get selceted product
-(void) getSelectedTurftype:(NSString*) getTurftype {
self.gotTurftype = getTurftype;
NSLog(@"self.gotTurftype %@", self.gotTurftype);
[self loadProductComponentValues];
if ([_turftypePopover isPopoverVisible]) {
[_turftypePopover dismissPopoverAnimated:YES];
}
}
-(void) initAllTheProduct {
_getProductType = [NSString stringWithString:AllProduct];
self.gotTurftype = nil;
// init the segment button value
[productTypeSelector setSelectedSegmentIndex:0];
[self loadProductComponentValues];
// Check Point
[TestFlight passCheckpoint:@"SET_ALL_PRODUCT"];
}
- (IBAction)setAllProduct:(id)sender {
[self initAllTheProduct];
}
// This Method use for Load Value of ProductComponent
- (NSMutableArray*) loadProductComponentValues {
[self.resultProduct removeAllObjects];
if (!_dbObject) [self loadDBAccessDatabase];
self.resultProduct = [[NSMutableArray alloc] initWithArray:[self.dbObject getRelatedProductArray:self.gotTurftype andProductType:_getProductType]];
[_productTableView reloadData];
return self.resultProduct;
}
- (NSMutableArray *) loadProductComponentValuesIfEmpty {
// NSLog(@"%s", __FUNCTION__);
[self initAllTheProduct];
if (!_dbObject) [self loadDBAccessDatabase];
if (!self.resultProduct || ![self.resultProduct count]) self.resultProduct = [[NSMutableArray alloc] initWithArray:[self.dbObject getRelatedProductArray:self.gotTurftype andProductType:_getProductType]];
// Check Point
[TestFlight passCheckpoint:@"LOAD_DATABASE"];
return self.resultProduct;
}
- (DBAccess *) loadDBAccessDatabase {
// NSLog(@"%s", __FUNCTION__);
if (!_dbObject) {
NSString * _dbFileName = @"turfnutritiontool.db";
_dbObject = [[DBAccess alloc] initWithSSDBAccessFilename:_dbFileName];
}
return _dbObject;
}
@end
//
//ProductComponentViewController.m
//草皮醇
//
//2011年10月14日由Aashish Joshi创建。
//版权所有2011 Abacus咨询服务。版权所有。
//
#导入“ProductComponentViewController.h”
#进口
@ProductComponentViewController的实现
@综合productTableView=\u productTableView;
@合成productTypeSelector=\u productTypeSelector;
@合成TurbtypePopover=\u TurbtypePopover;
@合成gottruptype=_gottruptype;
@合成resultProduct=\u resultProduct;
@合成productTableCellStyle=\u productTableCellStyle;
@合成dbObject=_dbObject;
@合成getProductType=\u getProductType;
#定义粒度@“G”
#定义液体@“L”
#定义Tankmix@“T”
#定义所有产品@“A”
-(id)initWithNibName:(NSString*)nibNameOrNil bundle:(NSBundle*)nibBundleOrNil
{
self=[super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
如果(自我){
//自定义初始化
}
回归自我;
}
-(无效)未收到记忆警告
{
//如果视图没有superview,则释放该视图。
[超级记忆警告];
//释放所有未使用的缓存数据、图像等。
}
#pragma标记-视图生命周期
-(无效)viewDidLoad
{
[超级视图下载];
//D o从nib加载视图后的任何附加设置。
UIColor*_background=[[UIColor alloc]initWithPatternImage:[UIImage IMAGENAME:@“main_bg.png”];
self.view.backgroundColor=\u background;
[_后台发布];
//初始化段按钮值
[productTypeSelector setSelectedSegmentIndex:0];
_getProductType=[[NSString alloc]initWithString:AllProduct];
//集合表委托
_productTableView.delegate=self;
//装载产品
[self-loadProductComponentValues];
//将表格视图设置为四舍五入
[[U productTableView图层]设置角半径:5.0];
}
-(无效)视图卸载
{
[self-setProductTableView:无];
[self-setProductTypeSelector:nil];
_productTableView=nil;
_productTypeSelector=nil;
_purptypepover=nil;
_类型=零;
_结果产品=无;
_productTableCellStyle=nil;
_getProductType=nil;
[[u getProductType发布];
[_productTableView发布];
[_productTypeSelector发布];
[_-poppover-release];
[_类型发布];
[_结果产品发布];
[_productTableCellStyle发布版];
[超级视频下载];
//释放主视图的所有保留子视图。
//例如,self.myOutlet=nil;
}
-(布尔)应自动旋转指针面定向:(UIInterfaceOrientation)interfaceOrientation
{
//对于支持的方向返回YES
返回YES;
}
-(无效)解除锁定{
[[u getProductType发布];
[_productTableView发布];
[_productTypeSelector发布];
[_-poppover-release];
[_类型发布];
[_结果产品发布];
[_productTableCellStyle发布版];
[super dealoc];
}
#pragma标记-表视图数据源
-(NSInteger)表格视图中的节数:(UITableView*)表格视图
{
//#警告可能不完整的方法实现。
//返回节数。
返回1;
}
-(NSInteger)表视图:(UITableView*)表视图行数节:(NSInteger)节
{
//#警告方法执行不完整。
//返回节中的行数。
//NSLog(@“%s”,函数);
返回[self.resultProduct count];
}
-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath
{
静态NSString*CellIdentifier=@“Cell”;
UITableViewCell*单元格=[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
如果(单元格==nil){
[[NSBundle mainBundle]loadNibNamed:@“productContentTableCellStyle”所有者:自选项:nil];
单元格=_productTableCellStyle;
self.productTableCellStyle=nil;
}
NSDictionary*\u productRow=[\u dbObject getProductdetail:[self.resultProduct objectAtIndex:indexPath.row]];
//配置单元格。。。
UILabel*_label=(UILabel*)[带标记的单元格视图:1];
NSString*_linkcode=[_productRowobjectforkey:@“linkcode”];
_label.text=\u linkcode;
_标签=(UILabel*)[带标签的单元格视图:2];
NSString*_description=[_productRowobjectforkey:@“description”];
_label.text=_说明;
_标签=(UILabel*)[带标签的单元格视图:3];
NSString*_productcode=[_productrowobjectforkey:@“productcode”];
_label.text=\u产品代码;
_标签=(UILabel*)[带标签的单元格视图:4];
NSString*_weight=[_productRowobjectforkey:@“weight”];
_label.text=_权重;
_标签=(UILabel*)[带标签的单元格视图:6];
NSNumber*.\U costperBag=[[NSNumber alloc]initWithFloat:[[U dbObject getUserProductCost:[self.resultProduct objectAtIndex:indexPath.row]]floatValue]];
_label.text=[@“$”stringByAppendingString:[[u costperBag stringValue]];
[_costperBag自动释放];
_getProductType=[\u productRow objectForKey:@“producttype”];
if([\u getProductType IsequalString:@“G”]){
_标签=(UILabel*)[带标签的单元格视图:10];
NSString*_weightTag=[[NSString alloc]initWithString:@“以磅为单位的重量”;
[_getProductType release];
[_productTableView release];
[_productTypeSelector release];
[_turftypePopover release];
[_gotTurftype release];
[_resultProduct release];
[_productTableCellStyle release];
_productTableView = nil;
_productTypeSelector = nil;
_turftypePopover = nil;
_gotTurftype = nil;
_resultProduct = nil;
_productTableCellStyle = nil;
_getProductType = nil;
_getProductType = [[NSString alloc] initWithString:AllProduct];
_getProductType = [[[NSString alloc] initWithString:AllProduct] retain];
_getProductType = [NSString stringWithString:AllProduct];
// First let's rename your property. In the .h file, modify the current declaration like so:
@property (nonatomic, copy) NSString *productType;
// In the .m file, change the @synthesize statement:
@synthesize productType = _productType;
// In cleaning up any compiler errors/warnings from references to the old names,
// modify code that directly assigns to the instance variable (other than in `dealloc`):
// So change this:
_getProductType = [NSString stringWithString:AllProduct];
// to the following:
self.productType = [NSString stringWithString:AllProduct];
// ...or better yet:
self.productType = AllProduct;
// Note that the above statement is equivalent to the following:
[self setProductType:AllProduct];