将记录加载到TableView - (更多按钮) [英] Loading records to a TableView - (More button)

查看:169
本文介绍了将记录加载到TableView - (更多按钮)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有100个记录要显示在表格上。但是我将只显示10条记录,当用户点击最后一行(这将有一个按钮,将说明加载下10个记录)表将行接下来的10条记录。

I have like 100 records to display on a table. But i will be only displaying 10 records, and when the user clicks the last row (Which will have a button that will say load the next 10 records) the table will row the next 10 records.

我已成功在最后一个单元格上显示更多按钮。但我不知道如何一次显示10个记录。我的代码到此为止;

I have displayed the more button on the last cell successfully. But i don't know how to display 10 records at a time. My code so far;

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];

上面将显示更多显示所有 100 记录。

The above would Display the More button after displaying all 100 records.

moreButtonClickAction b $ b

-(void)moreButtonClickAction {
NSLog(@"Suppose to load the next 10 records");
}

numberOfRowsInSection

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{

    return [self.arrayThatContainsAllHundredRecords count];
}



我需要一种方法来编辑此代码,所以我将只显示10条记录,并在用户单击更多按钮时显示下一个10。 (现在总记录应为20 - (由于点击更多按钮,所以前10个记录和10个记录))

I need a way to edit this code, so i will only display 10 records at a time, and display the next 10 when the user clicks the more button. (Now the total records should be 20 - (previous 10 + the 10 records as a result of clicking the more button ))

注意:我将下载所有100条记录并将其保存在 viewDidLoad 方法中的 self.arrayThatContainsAllHundredRecords

NOTE: I will be downloading all 100 records and saving it in self.arrayThatContainsAllHundredRecords in the viewDidLoad method.

我相信我必须在执行 [self.tableView reloadData]; 之前进行一些更改,告诉加载10条记录。

I believe that i have to make some change before executing [self.tableView reloadData];, as in tell to load 10 records.

好吧,假如我只有53条记录。然后用户将点击更多按钮5次,在第6个实例上,表应该只显示3个记录。如何在tableview中处理:numberOfRowsInSection:?

Well, say if i only had 53 records. Then the user will click the more button 5 times and on the 6th instance, the table should display only 3 records. How can this be handled in the tableview:numberOfRowsInSection: ?

推荐答案

tableView:numberOfRowsInSection:是确定将显示多少行的方法,因此第一步将是更改。在视图控制器中还需要一个属性来跟踪应该显示多少行。类似这样:

tableView:numberOfRowsInSection: is the method that determines how many rows will be shown, so the first step will be to change that. You also need a property in your view controller to keep track of how many rows should be visible. Something like this:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.numberOfRowsVisible;
}

当点击更多按钮时,必须增加该数字并重新加载tableView数据。

And when the more button is clicked, you have to increase that number and reload the tableView data.

-(void)moreButtonClickAction {
    if (self.numberOfRowsVisible < self.maxNumberOfRows) 
        self.numberOfRowsVisible = MIN(self.numberOfRowsVisible + 10, self.maxRows);
    [self.tableView reloadData];
}

这篇关于将记录加载到TableView - (更多按钮)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆