我有大约 100 条记录要显示在表格上。但我只会显示 10 条记录,当用户单击最后一行 (Which will have a button that will say load the next 10 records)
时该表将排列接下来的 10 条记录。
我已成功在最后一个单元格上显示更多按钮。但我不知道如何一次显示10条记录。到目前为止我的代码;
ViewDidLoad
self.arrayThatContainsAllHundredRecords= [NSArray arrayWithArray:hundredRecordsArray];
[self performSelector:@selector(addTheTableFooter:) withObject:nil afterDelay:0.5];
addTheTableFooter
UIView* footer = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 30)];
[footer addSubview:moreButton]; // i have also added an event to the button click see below, and i have not shown it here.
self.tableView.tableFooterView =footer;
[self.mainWindow removeFromSuperview];
[self.tableView reloadData];
以上将显示 More
显示全部后按钮100
记录。
更多按钮点击操作
-(void)moreButtonClickAction {
NSLog(@"Suppose to load the next 10 records");
}
节内行数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [self.arrayThatContainsAllHundredRecords count];
}
我需要一种方法来编辑此代码,因此我一次只会显示 10 条记录,并在用户单击 more
时显示下 10 条记录。按钮。 (现在总记录应为 20 -(前 10 条 + 单击 more
按钮后的 10 条记录))
注意:我将下载所有 100 条记录并将其保存在 self.arrayThatContainsAllHundredRecords
中在 viewDidLoad
方法。
我相信在执行 [self.tableView reloadData];
之前我必须做出一些改变,如告诉加载 10 条记录。
好吧,假设我只有 53 条记录。然后用户将单击“更多”按钮 5 次,在第 6 次时,表应仅显示 3 条记录。如何在 tableview:numberOfRowsInSection: 中处理这个问题?
最佳答案
tableView:numberOfRowsInSection:
是确定将显示多少行的方法,因此第一步是更改它。您还需要 View Controller 中的一个属性来跟踪应该可见的行数。像这样的事情:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return self.numberOfRowsVisible;
}
当单击“更多”按钮时,您必须增加该数字并重新加载 tableView 数据。
-(void)moreButtonClickAction {
if (self.numberOfRowsVisible < self.maxNumberOfRows)
self.numberOfRowsVisible = MIN(self.numberOfRowsVisible + 10, self.maxRows);
[self.tableView reloadData];
}
关于iphone - 将记录加载到 TableView -(“更多”按钮),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9179083/