В настоящее время мое приложение использует пользовательский модальный диалоговый объект, когда я жду веб-службы
@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];
}
Затем, после завершения веб-службы, я обычно называю демонтаж
- (void)returnWebServiceDetails:(MyClass *)obj
{
AddModalDialog* modal = [[AddModalDialog alloc] init];
[modal removeModalDialogForView:self];
[modal release];
}
Разве я не должен инициировать этот объект дважды и вместо этого иметь свойство? Новый разработчик obj-c ищет лучшую практику в этом направлении.
Заранее спасибо