目前我的應用程序使用時使用,當我在等待Web服務如何處理內存管理自定義模式對話框安裝/拆卸
@implementation AddModalDialog
- (void)buildModalDialogWithTextForView:(NSString *)text:(UIViewController *)controller
{
UIView* _hudView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 400, 450)];
_hudView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.5];
_hudView.clipsToBounds = YES;
UIActivityIndicatorView* _activityIndicatorView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
_activityIndicatorView.frame = CGRectMake(140, 135, _activityIndicatorView.bounds.size.width, _activityIndicatorView.bounds.size.height);
[_hudView addSubview:_activityIndicatorView];
[_activityIndicatorView startAnimating];
UILabel* _captionLabel = [[UILabel alloc] initWithFrame:CGRectMake(30, 190, 250, 22)];
_captionLabel.backgroundColor = [UIColor clearColor];
_captionLabel.textColor = [UIColor whiteColor];
_captionLabel.font = [UIFont systemFontOfSize:13.0];
_captionLabel.adjustsFontSizeToFitWidth = NO;
_captionLabel.textAlignment = UITextAlignmentCenter;
_captionLabel.text = text;
[_hudView addSubview:_captionLabel];
[controller.view addSubview:_hudView];
}
- (void)removeModalDialogForView:(UIViewController *)controller
{
NSUInteger i, count = [controller.view.subviews count];
[[controller.view.subviews objectAtIndex:(count - 1)] removeFromSuperview];
}
@end
我的問題是有關內存管理的自定義模式對話框對象這個對象。在上面的自定義UIView內可能會注意到的任何東西都是值得歡迎的,因爲它確實有改進的空間。
下面是我目前的工作瓦特/這在我的其他對象時,我想拉起模式
- (void)viewDidLoad
{
AddModalDialog* modal = [[AddModalDialog alloc] init];
[modal buildModalDialogWithTextForView:@"Loading some details ..." :self];
[modal release];
}
然後Web服務後完成我通常稱之爲推倒
- (void)returnWebServiceDetails:(MyClass *)obj
{
AddModalDialog* modal = [[AddModalDialog alloc] init];
[modal removeModalDialogForView:self];
[modal release];
}
我不應該初始化這個對象兩次,而是有一個屬性?新的obj-c開發人員正在尋找圍繞此行爲的最佳實踐。
預先感謝您
哇 - 這是一些答案!感謝您爲此付出的所有努力! – 2011-01-24 01:12:17