I have a table view containing parsed NSXML objects.
I want to implement an activityIndicator
in this tableview
, such that when data loading is complete the activityIndicator
stops automatically.
How to do this?
Thanks in advance
I have a table view containing parsed NSXML objects.
I want to implement an activityIndicator
in this tableview
, such that when data loading is complete the activityIndicator
stops automatically.
How to do this?
Thanks in advance
looks like you are not familiar with NSXmlParser
.
You should start activity
in this method:
– parserDidStartDocument:
Then you can stop activity
after the pasring stops in this delegate method:
– parserDidEndDocument:
You can refer to this apple doc for more information about NSXMLParser
delegate.
Use int totalRows
and Bool showSpinner
in your code,When call parsing method set showSpinner=YES & totalRows=1
initially show spinner in table view and reload table view,after loading data set totalRows count
and set showSpinner=NO
, reload tableview
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return totalRows;
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
NSString *identifier;
if(showSpinner)
{
identifier=@"spinnerCell";
UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:identifier];
if (cell==nil) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
cell.selectionStyle=UITableViewCellSelectionStyleNone;
UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
cell.contentView.backgroundColor=[UIColor whiteColor];
[cell.contentView addSubview:spinner];
spinner.tag = 123;
CGRect _frame = [spinner frame];
_frame.origin.y = 10;
_frame.origin.x= (cellwidth/2)-(_frame.size.width/2);
spinner.frame = _frame;
[spinner startAnimating];
}
UIActivityIndicatorView *spinner=(UIActivityIndicatorView*)[cell.contentView viewWithTag:123];
[spinner startAnimating];
}
else
{
identifier=@"dataCell";
UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:identifier];
if (cell==nil) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
//add your custom cell or data
}
}
return cell;
}
If you want to show an activity view inside cell, maybe next to title, you could use something like,
UIActivityIndicatorView *activityView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
[cell.imageView addSubview:activityView];
[activityView startAnimating];