UItableView实现分页效果(点击more再显示10条)
来源:互联网 发布:gif调色软件 编辑:程序博客网 时间:2024/05/19 02:25
实现的效果如下:self.myTableViewinsertRowsAtIndexPaths:insertIndexPathswithRowAnimation:UITableViewRowAnimationF
实现的效果如下:
点击 “More…”,实现后面的效果.
- 基本上就是数据源里先只放10条, 点击最后一个cell时, 添加更多的数据到数据源中.。
- 处理"加载更多"的那个cell的选择事件,触发一个方法来加载更多数据到列表。
- indexPathForRow插入数据。
#import<UIKit/UIKit.h>
@interfaceiphone_tableMoreViewController : UIViewController
<UITableViewDelegate,UITableViewDataSource>{
IBOutletUITableView *myTableView;
NSMutableArray *items;
}
@property (nonatomic,retain) UITableView *myTableView;
@property (nonatomic,retain) NSMutableArray *items;
@end#import"iphone_tableMoreViewController.h"
@implementation iphone_tableMoreViewController
@synthesize items,myTableView;
- (void)viewDidLoad {
[superviewDidLoad];
items=[[NSMutableArray alloc] initWithCapacity:0];
for (inti=0; i<10; i++) {
[items addObject:[NSString stringWithFormat:@"cell %i",i]];
}
}
- (void)didReceiveMemoryWarning {
[superdidReceiveMemoryWarning];
}- (void)viewDidUnload{
items=nil;
self.myTableView=nil;
}
- (void)dealloc {
[self.myTableView release];
[itemsrelease];
[superdealloc];
}-(NSInteger)tableView:(UITableView *)tableViewnumberOfRowsInSection:(NSInteger)section {
int count =[items count];
return count + 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableViewcellForRowAtIndexPath:(NSIndexPath *)indexPath {
staticNSString *tag=@"tag";
UITableViewCell *cell=[tableViewdequeueReusableCellWithI dentifier:tag];
if(cell==nil) {
cell=[[[UITableViewCell alloc] initWithFrame:CGRectZero
reuseIdentifier:tag] autorelease];
}
if([indexPath row] == ([items count])) {
//创建loadMoreCell
cell.textLabel.text=@"More..";
}else{
cell.textLabel.text=[items objectAtIndex:[indexPathrow]];
}
returncell;
}
- (void)tableView:(UITableView *)tableViewdidSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row == [items count]) {
UITableViewCell *loadMoreCell=[tableViewcellForRowAtIndexPath:indexPath];
loadMoreCell.textLabel.text=@"loading more …";
[self performSelectorInBackgro und:@selector(loadMore)withObject:nil];
[tableView deselectRowAtIndexPath:indexPathanimated:YES];
return;
}
//其他cell的事件
}
-(void)loadMore
{
NSMutableArray *more;
more=[[NSMutableArray alloc] initWithCapacity:0];
for (inti=0; i<10; i++) {
[more addObject:[NSString stringWithFormat:@"cell ++%i",i]];
}
//加载你的数据
[selfperformSelectorOnMainThr ead:@selector(appendTableWith:)withObject:more waitUntilDone:NO];
[morerelease];
}
-(void) appendTableWith:(NSMutableArray *)data
{
for (inti=0;i<[data count];i++) {
[items addObject:[data objectAtIndex:i]];
}
NSMutableArray *insertIndexPaths = [NSMutableArrayarrayWithCapacity:10];
for (int ind= 0; ind < [data count]; ind++) {
NSIndexPath *newPath = [NSIndexPath indexPathForRow:[itemsindexOfObject:[data objectAtIndex:ind]] inSection:0];
[insertIndexPaths addObject:newPath];
}
[self.myTableViewinsertRowsAtIndexPaths:insertIndexPathswithRowAnimation:UITableViewRowAnimationF ade];
}
@end
- UItableView实现分页效果(点击more再显示10条)
- UITableView实现分页显示
- UITableView实现分页显示
- UITableView实现分页显示
- UItableView实现分页效果(…
- iphone开发 UITableview实现分页显示方法(代码)
- UITableView 实现分页显示的代码
- UITableView 实现分页显示的代码
- IOS 之 UITableView 实现点击展开裂缝效果
- UItableview点击后的折叠效果的简单实现
- js实现点击显示效果[select]
- web前端 点击显示大图效果实现
- iOS-UITableView 实现分页显示的代码
- jQuery实现“分页”的效果,控制div分页显示
- 分页,显示条数
- table分页点击最后一页按钮不是显示剩余条数,而是默认显示每页条数
- JQ实现效果:点击(or鼠标滑过)连接时显示内容,再点击(鼠标滑出)连接时隐藏内容
- (原创)另类的[分页显示效果]?!
- 简单号码分配器的实现分析
- Android Loop&Handle学习总结
- 改变键盘的颜色
- 黑马程序员_String类
- NSNavgationController自定义切换画面(传送参数)
- UItableView实现分页效果(点击more再显示10条)
- 允许对cell进行编辑和拖动
- android手机之间用wifi direct通信
- !!!!!!!!!!!
- UIimage的缩放线程实现安全和非线程安全操作
- android+WM9714(AC97)调试
- ChartDirector 5.0 for python 笔记【5】Side Label Layout
- UIimage扩展-缩放,裁切,改变大小-合并-保存到媒体库
- C#带复选框的日历控件,本人原创