I am new to iphone development.I want to display an activity indicator when navigating form one UITableView1 to another UITableView2 and stops when the table is completely loaded.I am using xml parsing to get the cell content of UITableView2.Please help me out.Please refer to some sample codes or tutorial.Thanks.
views:
724answers:
2
+2
A:
Following code may help you...
in .h file of UITableView2:
declare variable
UIActivityIndicatorView *progressInd;
create property
@property (nonatomic, retain) UIActivityIndicatorView *progressInd;
and declare method
- (UIActivityIndicatorView *)progressInd;
in .m file of UITableView2:
@synthesize progressInd;
define this method (adjust x,y,width,width position)
- (UIActivityIndicatorView *)progressInd {
if (progressInd == nil)
{
CGRect frame = CGRectMake(self.view.frame.size.width/2-15, self.view.frame.size.height/2-15, 30, 30);
progressInd = [[UIActivityIndicatorView alloc] initWithFrame:frame];
[progressInd startAnimating];
progressInd.activityIndicatorViewStyle = UIActivityIndicatorViewStyleGray;
[progressInd sizeToFit];
progressInd.autoresizingMask = (UIViewAutoresizingFlexibleLeftMargin |
UIViewAutoresizingFlexibleRightMargin |
UIViewAutoresizingFlexibleTopMargin |
UIViewAutoresizingFlexibleBottomMargin);
progressInd.tag = 1; // tag this view for later so we can remove it from recycled table cells
}
return progressInd;
}
in - (void)viewDidLoad
method where your parsing starts
[self.view addSubview:self.progressInd];
use following line where your parsing ends
[self.progressInd removeFromSuperview];
Ruchir Shah
2010-01-28 10:16:01
Thanks. It was working fine.
Warrior
2010-01-28 10:36:12
A:
It wasn't working fine in my case. This is how my viewDidLoad look like:
(void) viewDidLoad
{
[self.view addSubview:self.progressInd];
//start parsing XML
if ([lTArray count] == 0)
{
NSString *path = [[NSBundle mainBundle] pathForResource:@"MT" ofType:@"plist"];
NSMutableArray *tmpArray = [[NSMutableArray alloc] initWithContentsOfFile:path];
NSString * r_path = [[tmpArray objectAtIndex:6] copy];
[tmpArray release];
XML_TableTab_Parse *xml_TableParse = [[XML_TableTab_Parse alloc] init];
[xml_TableParse parseXMLFileAtURL:r_path];
lTArray = [xml_TableParse.tRArray copy];
[lTView reloadData];
}
//finish parsing XML
[self.progressInd removeFromSuperview];
[super viewDidLoad];
}
The issue is that the indicator did not appear till the viewDidLoad method finish. The viewDidLoad is the long method in my case.
Please assist, Thanks!
devasenapati
2010-07-04 17:29:28