Iphone 如何在UITableView上添加UIActivityIndicator
我想尝试Iphone 如何在UITableView上添加UIActivityIndicator,iphone,objective-c,ios,Iphone,Objective C,Ios,我想尝试UIActivityIndicator和UITableView当iphone上第一次加载表时,活动必须开始闪烁,当iphone上的表完全加载时,当我单击“加载更多单元格”时,我还想在加载更多行时显示活动闪烁。请告诉我如何做到这一点如果您自己完成此代码,请提前感谢 #import "RootViewController.h" #import "Tweet.h" @implementation RootViewController @synthesize customImage,pag
UIActivityIndicator
和UITableView
当iphone上第一次加载表时,活动必须开始闪烁,当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
#导入“RootViewController.h”
#导入“Tweet.h”
@RootViewController的实现
@合成自定义图像、页面控件、单元格//索引;
#布拉格标记-
#pragma标记视图生命周期
-(无效)viewDidLoad
{
页面大小=2;
//totalpages=(NSInteger)(xmlParser.tweets)/5;
xmlParser=[[xmlParser alloc]loadXMLByURL:@”http://api.twitter.com/1/statuses/user_timeline/KentFranks.xml"];
[超级视图下载];
self.title=@“Tweets”;
}
#布拉格标记-
#pragma标记表视图数据源
-(NSInteger)表格视图中的节数:(UITableView*)表格视图
{
返回1;
}
-(NSInteger)表视图:(UITableView*)表视图行数节:(NSInteger)节
{
if([xmlParser.tweets count]>pageSize)
{
返回页面大小+1;
}
返回xmlParser.tweets.count;
}
-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath
{
静态NSString*CellIdentifier=@“Cell”;
cell=[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
如果(单元格==nil){
cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle重用标识符:CellIdentifier]自动释放];
}
//UIImage*twitterLogo=[[UIImage ImageName:@“twitter logo.png”]自动删除];
NSString*imagepath=[[NSBundle mainBundle]pathForResource:@“twitter logo”类型:@“png”];
UIImage*image=[[UIImage alloc]initWithContentsOfFile:imagepath];
cell.imageView.image=图像;
cell.detailTextLabel.text=@“在此处添加字幕”;
Tweet*currentTweet=[[xmlParser tweets]objectAtIndex:indexath.row];
如果(indexPath.row尝试此代码,可能会对您有所帮助
将微调器直接添加到单元格视图中感觉有点粗糙,因此我使用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;
这将生成一个如下所示的单元格:
这可能会对您有所帮助
第二个选择是
我有问题,我只想在我单击的单元格上显示活动指示器,它必须停止在我已单击的单元格上设置动画。但在您的代码中,它仍在我单击的每个单元格上设置动画。请解决此问题。在未选中时,您可以通过单击任何索引来停止动画。行单元格选举