本文共 3978 字,大约阅读时间需要 13 分钟。
转载自:
@interface FooterViewTestViewContro
// 表格数据数组,因为是演示代码,直接定义为数组
NSMutableArray *tableData;
NSMutableArray *tableMoreData;
NSUInteger dataNumber;
BOOL _loadingMore;
UITableView *table;
}
@property (nonatomic, retain) UITableView *table;
@property (nonatomic, retain) NSMutableArray *tableData;
@property (nonatomic, retain) NSMutableArray *tableMoreData;
// 创建表格底部
- (void) createTableFooter;
// 开始加载数据
- (void) loadDataBegin;
// 加载数据中
- (void) loadDataing;
// 加载数据完毕
- (void) loadDataEnd;
@end
@implementation FooterViewTestViewContro
@synthesize table;
@synthesize tableData;
@synthesize tableMoreData;
- (void)viewDidLoad {
table = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 320, 460) style:UITableViewStylePlain];
table.delegate = self;
table.dataSource = self;
[self.view addSubview:table];
tableData = [[NSMutableArray alloc] initWithObjects:
@"January",@"February",@"March",@"April",@"May",@"June",
@"July",@"August",@"September",@"October",@"November",@"December",nil];
tableMoreData = [[NSMutableArray alloc] initWithObjects:@"BAIDU",@"GOOGLE",@"FACEBOOK",@"YAHOO",nil];
[self createTableFooter];
}
#pragma mark -
#pragma mark Table view data source
// Customize the number of sections in the table view.
- (NSInteger)numberOfSectionsInTableV
}
// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
cell.textLabel.text = [tableData objectAtIndex:indexPath.row];
}
- (void)scrollViewDidEndDragging
{
if(!_loadingMore && scrollView.contentOffset.y > ((scrollView.contentSize.height - scrollView.frame.size.height)))
{
[self loadDataBegin];
}
}
// 开始加载数据
- (void) loadDataBegin
{
[self loadDataing];
}
// 加载数据中
- (void) loadDataing
{
dataNumber = [tableData count];
for (int x = 0; x < [tableMoreData count]; x++)
{
[tableData addObject:[tableMoreData objectAtIndex:x]];
}
[[self table] reloadData];
[self loadDataEnd];
}
// 加载数据完毕
- (void) loadDataEnd
{
_loadingMore = NO;
[self createTableFooter];
}
// 创建表格底部
- (void) createTableFooter
{
}
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
}
@end