0

我想知道何时首次加载 iphone 活动UIActivityIndicatorUITableView表加载必须开始闪烁,以及当我单击加载更多单元格时表在 iphone 中完全加载时,我还想在加载更多行时显示活动闪烁请告诉我如果您自己完成此代码,我该怎么做,这是代码,然后在此先感谢

#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
4

2 回答 2

1

试试这个代码可能对你有帮助......

将微调器直接添加到单元格视图感觉有点 hacky,所以我使用 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;

这给出了一个如下所示的单元格:

加载单元

于 2012-11-06T07:23:06.823 回答
0

这可能会帮助你 https://github.com/pothibo/PHRefreshTriggerView 这是 PHRefreshTriggview

第二个选项是 https://github.com/enormego/EGOTableViewPullRefresh

现在这是第二张图片

于 2012-11-06T07:42:45.397 回答