views:

19

answers:

1

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...

+2  A: 

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
vodkhang
Bingo... Though it would be something link that, I just couldn't get the code right...
jimbo