Removing subview for activity indicator
I have built a new view with an activity indicator attached, loading this nib, seems to be working fine on another view:
- (void)viewDidLoad {
[super viewDidLoad];
ProgressViewController *progresssView = [[ProgressViewController alloc] initWithNibName:@"ProgressViewController" bundle:nil];
[self.view addSubview:progresssView.view];
}
The problem is when I try and remove the view when 开发者_开发知识库the data has been loaded:
- (void)parserDidEndDocument:(NSXMLParser *)parser {
ProgressViewController *progresssView = [[ProgressViewController alloc] initWithNibName:@"ProgressViewController" bundle:nil];
[progresssView.view removeFromSuperview];
NSLog(@"All done");
[dataTable reloadData];
}
Any help welcome...
You cannot do in that way because your new progress indicator is not the same as the one added.
The way you can do (if both methods in the same class) is declare an instance variable and a property for it.
@interface MyViewController {
@private
ProgressViewController *progresssView;
}
@property (nonatomic, retain) ProgressViewController *progresssView;
@end
@implementation MyViewController
@synthesize progressView;
- (void)viewDidLoad {
[super viewDidLoad];
self.progresssView = [[ProgressViewController alloc] initWithNibName:@"ProgressViewController" bundle:nil] autorelease];
[self.view addSubview:progresssView.view];
}
- (void)parserDidEndDocument:(NSXMLParser *)parser {
[self.progresssView.view removeFromSuperview];
[dataTable reloadData];
}
- (void)dealloc {
[progressView release];
}
@end
精彩评论