我正在开发一个iphone应用程序,它使用非常简单的界面并在后端进行数据库处理。我也启用了ARC OPTION。 我的viewDidLoad方法如下:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
/*********needed to implement scroll view********/
svScroll.frame = CGRectMake(0, 0, 320, 460);
svScroll.contentSize = CGSizeMake(320, 800);
/*********************************************/
//[DataHelper openDbCompany];
NSString *date=[DataHelper getFinYr];
[btDate setTitle:[DataHelper dateSqliteToNormal:date] forState:UIControlStateNormal];
arrayUnitsMeasure=[[NSMutableArray alloc]initWithArray:[DataHelper getUnitsOfMeasure]];
//[DataHelper closeDbCompany];
tfValue.keyboardType=UIKeyboardTypeDecimalPad;
tfQuantity.keyboardType=UIKeyboardTypeDecimalPad;
tfCostUnit.keyboardType=UIKeyboardTypeDecimalPad;
//catching the notification for text field value change.
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(textFieldChanged:) name:UITextFieldTextDidChangeNotification object:tfQuantity];
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(textFieldChanged:) name:UITextFieldTextDidChangeNotification object:tfCostUnit];
}
我的.h文件包含IBOutlets,其定义如下:
@interface
Create_Inventory_Item:UIViewController<Date_Picker_Protocol,Picker_View_Protocol,UITextFieldDelegate>
{
IBOutlet UIScrollView *svScroll;
IBOutlet UITextField *tfItemName;
IBOutlet UILabel *lbUnitsOfMeasure;
IBOutlet UIButton *btSelectUnitsMeasure;
IBOutlet UIButton *btDate;
IBOutlet UINavigationBar *btBack;
IBOutlet UITextField *tfQuantity;
IBOutlet UITextField *tfCostUnit;
IBOutlet UITextField *tfValue;
IBOutlet UIButton *btCreate;
NSMutableArray *arrayUnitsMeasure;
UIButton *btKeyboardDone;
UIView *accessoryView;
UITextField *txtActiveField;
UIButton *btMinus;
Picker_View *callPickerView;
Date_Picker *callDatePicker;
}
@property(nonatomic,retain) UIButton *btMinus;
@property(nonatomic,retain)UITextField *txtActiveField;
@property(nonatomic,retain) UIButton *btKeyboardDone;
@property(nonatomic,retain)UIView *accessoryView;
@property(nonatomic,retain) IBOutlet UINavigationBar *btBack;
@property(nonatomic,retain)IBOutlet UIScrollView *svScroll;
@property(nonatomic,retain)IBOutlet UITextField *tfItemName;
@property(nonatomic,retain)IBOutlet UILabel *lbUnitsOfMeasure;
@property(nonatomic,retain)IBOutlet UIButton *btSelectUnitsMeasure;
@property(nonatomic,retain) IBOutlet UIButton *btDate;
@property(nonatomic,retain) IBOutlet UITextField *tfQuantity;
@property(nonatomic,retain) IBOutlet UITextField *tfCostUnit;
@property(nonatomic,retain)IBOutlet UITextField *tfValue;
@property(nonatomic,retain) IBOutlet UIButton *btCreate;
-(IBAction)btSelectUnitsMeasure:(id)sender;
-(IBAction)btDate:(id)sender;
-(IBAction)btCreate:(id)sender;
-(IBAction) hideKeyboard:(id)sender;
-(IBAction)showAlerView:(NSString *)message;
-(IBAction)btBack:(id)sender;
请告诉我在dealloc和viewDidUnloadMethod中我需要做什么? 我正在使用ARC OPTION 此外,当我在模拟器中运行带有配置文件选项的应用程序以进行内存分配和泄漏时,它有时会显示MEMORY LEVEL LOW WARNING和MEMORY LEVEL NORMAL。造成这种情况的原因是什么?
答案 0 :(得分:0)
如果你正在使用ARC,你只需要一个dealloc来取消该类实例中所有基于对象的成员。
所有应用程序偶尔会收到内存警告。您可以选择通过撤消稍后可以延迟初始化的成员进行响应。
在我的应用程序中,我在viewWillAppear中懒惰初始化大多数可视成员(UIViews等...)并在viewDidDisappear方法中积极释放。这样,只有2个视图可以一次初始化它们(在视图控制器转换期间),当该视图是唯一可见的视图时,只有1个视图。
因此,除了操作大图像等时,我得到的内存警告很少。