How can i add a activity indicator below the UITableView?(如何在 UITableView 下方添加活动指示器?)
问题描述
在我的应用程序中,我想在 UItableview 下添加活动指示器,其中 tableview 将滚动,但我不知道如何在此处添加活动指示器.
In my application i want to add activity indicator under UItableview where tableview will scroll but i do not know how can i add activity indicator over there.
详细说明,当我完成 tableview 的滚动时,对于更多数据,我必须通过活动指示器设置刷新选项.
To elaborate,when i will finish the scrolling of tableview then for more data i have to set a refresh option by an activity indicator.
我已经在 tableview 的顶部尝试过它并且它有效,但我不知道如何将它添加到 tableview 下方.这是一些示例代码..
i have tried it at the top of the tableview and it worked but i dont know how can i add it below the tableview. here is some sample code..
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
if (isLoading) return;
isDragging = YES;
refreshHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, scrollView.contentOffset.y + REFRESH_HEADER_HEIGHT, 320, REFRESH_HEADER_HEIGHT)];
refreshHeaderView.backgroundColor = [UIColor clearColor];
refreshLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, scrollView.contentOffset.y + REFRESH_HEADER_HEIGHT, 320, REFRESH_HEADER_HEIGHT)];
refreshLabel.backgroundColor = [UIColor clearColor];
refreshLabel.font = [UIFont boldSystemFontOfSize:12.0];
refreshLabel.textAlignment = UITextAlignmentCenter;
refreshArrow = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"refresharrow.png"]];
refreshArrow.frame = CGRectMake((scrollView.contentOffset.y + REFRESH_HEADER_HEIGHT - 27) / 2,
(scrollView.contentOffset.y + REFRESH_HEADER_HEIGHT - 44) / 2,
27, 44);
refreshSpinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
refreshSpinner.frame = CGRectMake((scrollView.contentOffset.y + REFRESH_HEADER_HEIGHT - 20) / 2, (scrollView.contentOffset.y + REFRESH_HEADER_HEIGHT - 20) / 2, 20, 20);
refreshSpinner.hidesWhenStopped = YES;
[refreshHeaderView addSubview:refreshLabel];
[refreshHeaderView addSubview:refreshArrow];
[refreshHeaderView addSubview:refreshSpinner];
[tableview addSubview:refreshHeaderView];
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
if (isLoading) {
// Update the content inset, good for section headers
if (scrollView.contentOffset.y > 0){
NSLog(@"scrollView.contentOffset.y 1= %d",scrollView.contentOffset.y );
tableview.contentInset = UIEdgeInsetsZero;
}
else if (scrollView.contentOffset.y >= -REFRESH_HEADER_HEIGHT){
NSLog(@"scrollView.contentOffset.y 2= %d",scrollView.contentOffset.y );
tableview.contentInset = UIEdgeInsetsMake(-scrollView.contentOffset.y, 0, 0, 0);
}
} else if (isDragging && scrollView.contentOffset.y > scrollView.contentOffset.y + REFRESH_HEADER_HEIGHT) {
// Update the arrow direction and label
[UIView beginAnimations:nil context:NULL];
if (scrollView.contentOffset.y > scrollView.contentOffset.y + REFRESH_HEADER_HEIGHT) {
// User is scrolling above the header
NSLog(@"scrollView.contentOffset.y 3= %d",scrollView.contentOffset.y );
refreshLabel.text = self.textRelease;
[refreshArrow layer].transform = CATransform3DMakeRotation(M_PI, 0, 0, 1);
} else { // User is scrolling somewhere within the header
refreshLabel.text = self.textPull;
[refreshArrow layer].transform = CATransform3DMakeRotation(M_PI * 2, 0, 0, 1);
}
[UIView commitAnimations];
}
}
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
if (isLoading) return;
isDragging = NO;
if (scrollView.contentOffset.y >= scrollView.contentOffset.y + REFRESH_HEADER_HEIGHT) {
// Released above the header
[self startLoading];
}
}
所以请有人给我一些示例代码,说明我该怎么做.
so please someone give me some example code about how can i do that.
实际上我是 iphone 应用程序开发的新手.所以请帮助我.
actually i am new in iphone application development.So please help me.
提前致谢.
推荐答案
添加活动指示器的最佳方式是在tableview的页脚.
The best way to add activity indicator is at footer of tableview.
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
UIView *headerView = [[[UIView alloc] init]autorelease];
[headerView setBackgroundColor:[UIColor clearColor]];
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:self
action:@selector(aMethod:)
forControlEvents:UIControlEventTouchDown];
[button setTitle:@"Load More" forState:UIControlStateNormal];
button.frame = CGRectMake(10.0, 210.0, 160.0, 40.0);
[headerView addSubview:button];
[headerLabel release];
return headerView;
}
向footerView 添加一个按钮并将操作设置为按钮(根据需要).这就是应用商店表格视图的工作方式.点击按钮获取更多数据添加到表格数组中滚动表格而不动画.
Add a button to the footerView and set action to button (as you needed). This how app store tableview works. On clicking button fetch some more data add to table array scroll the table without animation.
这篇关于如何在 UITableView 下方添加活动指示器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 UITableView 下方添加活动指示器?
基础教程推荐
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01