0
votes

i want to attech UIActivityIndicator with UITableView when then first time table load on iphone activity must start blinking and when the table compleletely load in iphone when i click on load more cell then also i want to show activity blink for that moment when more rows loading kindly tell me how can i do that this is the code if you complete this code by your self then thanks in advance

#import "RootViewController.h"
#import "Tweet.h"


@implementation RootViewController

@synthesize customImage,pagecontrol,cell;//indexPath;

#pragma mark -
#pragma mark View lifecycle


- (void)viewDidLoad 
{
    pageSize = 2;

       // totalpages =(NSInteger) (xmlParser.tweets)/5 ;
    xmlParser = [[XMLParser alloc] loadXMLByURL:@"http://api.twitter.com/1/statuses/user_timeline/KentFranks.xml"];


    [super viewDidLoad];

    self.title = @"Tweets";

}





#pragma mark -
#pragma mark Table view data source


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{
    return 1;
}



- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{
    if([xmlParser.tweets count]>pageSize)
    {
        return pageSize+1;
    }
    return  xmlParser.tweets.count;
    }



- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{

    static NSString *CellIdentifier = @"Cell";

    cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];

    }


    //UIImage    *twitterLogo = [[UIImage imageNamed:@"twitter-logo.png"]autorelease];

    NSString *imagepath = [[NSBundle mainBundle] pathForResource:@"twitter-logo" ofType:@"png"];

    UIImage *image =[[ UIImage alloc] initWithContentsOfFile:imagepath];
    cell.imageView.image = image;



    cell.detailTextLabel.text= @"Add Subtitle here";

    Tweet *currentTweet = [[xmlParser tweets] objectAtIndex:indexPath.row];
    if(indexPath.row<pageSize)

    {
        cell.textLabel.text = currentTweet.content;
    }

    else
    {


cell.textLabel.text = @"Load more ";
}


        NSLog(@"cell: %@",cell);
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    return cell;


}

-(IBAction)loadmorebutton:(id)sender;
{

    NSIndexPath *currentPath = [self.tableView indexPathForSelectedRow];
    NSIndexPath *nextPath = [NSIndexPath indexPathForRow:currentPath.row+1 inSection:currentPath.section];
    [self.tableView selectRowAtIndexPath:nextPath animated:YES scrollPosition:UITableViewScrollPositionMiddle];
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath  *)indexPath{


    if (indexPath.row==pageSize) 
    {
        pageSize=pageSize+2;
        [tableView reloadData];

    }

}

/*
 -(IBAction)pagecontrol:(UIPageControl *)pageControl
 {
    [self.tableView reloadData];
}
 -(IBAction)Pageindexchanges:(id)sender
{
    NSLog(@"clicked page index: %i ",pagecontrol.currentPage);

}
*/
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 55;
}

#pragma mark -
#pragma mark Table view delegate

/*- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{

}
*/

#pragma mark -
#pragma mark Memory management

- (void)didReceiveMemoryWarning 
{

    [super didReceiveMemoryWarning];

}

- (void)viewDidUnload 
{

}


- (void)dealloc 
{
    [xmlParser release];
    [super dealloc];
}


@end
2

2 Answers

1
votes

Try this code may be helped you...

Add the spinner directly to the cell view felt a little hacky, so I used a 1x1 transparent png as the image view and resized it to be whatever my spinner size is:

UITableViewCell *cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"NoReuse"] autorelease];
cell.textLabel.text = @"Loading...";

UIActivityIndicatorView *spinner = [[[UIActivityIndicatorView alloc] 
     initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray] autorelease];

// Spacer is a 1x1 transparent png
UIImage *spacer = [UIImage imageNamed:@"spacer"];

UIGraphicsBeginImageContext(spinner.frame.size);

[spacer drawInRect:CGRectMake(0,0,spinner.frame.size.width,spinner.frame.size.height)];
UIImage* resizedSpacer = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();
cell.imageView.image = resizedSpacer;
[cell.imageView addSubview:spinner];
[spinner startAnimating];

return cell;

That gives a cell that looks like this:

loading cell