2012-11-06 73 views
0

我想attech UIActivityIndicatorUITableView那麼當第一次在iphone上的表活動加載必須開始閃爍,當表完全加載在iphone上時,當我點擊加載更多的單元格時,我也想顯示那一刻活動眨眼時更行敬請裝載告訴我,我該怎麼辦,這是代碼,如果你提前我怎麼可以在UITableView上添加UIActivityIndi​​cator

#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 

回答

1

完成你的自我,然後感謝這個代碼試試這個代碼可以幫助你...

添加微調直接到細胞視圖感覺有點哈克,所以我用1x1透明PNG作爲圖像視圖,並調整它是什麼我的微調尺寸是:

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; 

給出單元,看起來像這樣:

loading cell

+0

,我與它的問題,我只是想表明對細胞活動的指標,在​​我點擊它必須停止動畫對細胞會上我已經點擊。但在你的代碼它仍然是動畫每先前的單元格,我點擊好心解決他的問題 – adnan

+0

在didselected你可以通過點擊任何index.row單元格選擇停止動畫 –

相關問題