-1

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

Adnan Aftab
  • 14,377
  • 4
  • 45
  • 54
Praphin SP
  • 69
  • 1
  • 14
  • Have you tried anything? Are you having difficulty with any particular part? As it stands, this is quite a broad question. – Abizern Feb 03 '14 at 10:16

3 Answers3

1

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.

https://developer.apple.com/library/mac/documentation/cocoa/reference/NSXMLParserDelegate_Protocol/Reference/Reference.html

Vaibhav Saran
  • 12,848
  • 3
  • 65
  • 75
1

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;
}
NANNAV
  • 4,875
  • 4
  • 32
  • 50
0

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];
Marco
  • 6,692
  • 2
  • 27
  • 38