hey, Could any one guide me through this I have around 15 entries in table I would like another 15 to come up with the load more in last UITableViewCell. could anyone help me?
嘿,任何人都可以指导我通过这个我在表中有大约15个条目我希望另外15个在最后的UITableViewCell中提出更多的负载。谁有人帮我?
4 个解决方案
#1
19
to show an extra row in the tableview, in
在tableview中显示一个额外的行
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return dataRows+1;
}
In
在
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
//after setting tableviewcell
if(indexPath.row==dataRows){
cell.textLabel.text=@"Load More Rows";
}
}
In
在
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if(indexPath.row==dataRows){
//there you can write code to get next rows
}
}
You need to update the numberOfRows variable according to the displayed rows.
您需要根据显示的行更新numberOfRows变量。
Edit: After fetching the extra entries, you can add them to the existing entries array using the following method. Your original array should be a NSMutableArray
to use this method.
编辑:获取额外条目后,可以使用以下方法将它们添加到现有条目数组中。您的原始数组应该是NSMutableArray以使用此方法。
[originalEntriesArray addObjectsFromArray:extraEntriesArray];
[originalEntriesArray addObjectsFromArray:extraEntriesArray];
#2
8
I wrote an example project that does just this. Download it from GitHub https://github.com/Abizern/PartialTable
我写了一个这样做的示例项目。从GitHub https://github.com/Abizern/PartialTable下载
#3
4
I wrote something that might be helpful : https://github.com/nmondollot/NMPaginator
我写了一些可能有用的东西:https://github.com/nmondollot/NMPaginator
It encapsulates pagination, and works with pretty much any webservice using page and per_page parameters. It also features a UITableView with automatic fetching of next results as you scroll down.
它封装了分页,并使用page和per_page参数与几乎任何web服务一起使用。它还具有UITableView,可在您向下滚动时自动获取下一个结果。
#4
1
hope this helps
希望这可以帮助
I took an Mutable array and an integer variable and set the total count of the array to the integer variable
我获取了一个Mutable数组和一个整数变量,并将数组的总数设置为整数变量
arr = [[NSMutableArray alloc]initWithObjects:@"Radix",@"Riki", nil]; dataRows = [arr count];
and then i set the number of rows in the sections as per the integer variable in the datasource method of the table
然后我根据表的datasource方法中的整数变量设置节中的行数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { // Return the number of rows in the section. return dataRows+1; }
because you wanted an extra cell at the end.
因为你最后想要一个额外的细胞。
Now its time to set the text of the table cell
现在是时候设置表格单元格的文本了
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{ static NSString *CellIdentifier = @"Cell";
{static NSString * CellIdentifier = @“Cell”;
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
// Configure the cell...
//setting the text of the cell as per Mutable array
if (indexPath.row < [arr count]) {
cell.textLabel.text = [arr objectAtIndex:indexPath.row];
}
//setting the text of the extra cell
if (indexPath.row == dataRows) {
cell.textLabel.text = @"more cells";
}
return cell;
}
}
now on the hit of the more cells cell you want extra cells right so just add your code inside the
现在,在更多单元格单元格的命中,您需要额外的单元格,所以只需添加您的代码
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
method, means you have to do something like this
方法,意味着你必须做这样的事情
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { if(indexPath.row == dataRows) { //code for exra cells please } }
Run your app to check this code out.
运行您的应用以检查此代码。
#1
19
to show an extra row in the tableview, in
在tableview中显示一个额外的行
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return dataRows+1;
}
In
在
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
//after setting tableviewcell
if(indexPath.row==dataRows){
cell.textLabel.text=@"Load More Rows";
}
}
In
在
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if(indexPath.row==dataRows){
//there you can write code to get next rows
}
}
You need to update the numberOfRows variable according to the displayed rows.
您需要根据显示的行更新numberOfRows变量。
Edit: After fetching the extra entries, you can add them to the existing entries array using the following method. Your original array should be a NSMutableArray
to use this method.
编辑:获取额外条目后,可以使用以下方法将它们添加到现有条目数组中。您的原始数组应该是NSMutableArray以使用此方法。
[originalEntriesArray addObjectsFromArray:extraEntriesArray];
[originalEntriesArray addObjectsFromArray:extraEntriesArray];
#2
8
I wrote an example project that does just this. Download it from GitHub https://github.com/Abizern/PartialTable
我写了一个这样做的示例项目。从GitHub https://github.com/Abizern/PartialTable下载
#3
4
I wrote something that might be helpful : https://github.com/nmondollot/NMPaginator
我写了一些可能有用的东西:https://github.com/nmondollot/NMPaginator
It encapsulates pagination, and works with pretty much any webservice using page and per_page parameters. It also features a UITableView with automatic fetching of next results as you scroll down.
它封装了分页,并使用page和per_page参数与几乎任何web服务一起使用。它还具有UITableView,可在您向下滚动时自动获取下一个结果。
#4
1
hope this helps
希望这可以帮助
I took an Mutable array and an integer variable and set the total count of the array to the integer variable
我获取了一个Mutable数组和一个整数变量,并将数组的总数设置为整数变量
arr = [[NSMutableArray alloc]initWithObjects:@"Radix",@"Riki", nil]; dataRows = [arr count];
and then i set the number of rows in the sections as per the integer variable in the datasource method of the table
然后我根据表的datasource方法中的整数变量设置节中的行数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { // Return the number of rows in the section. return dataRows+1; }
because you wanted an extra cell at the end.
因为你最后想要一个额外的细胞。
Now its time to set the text of the table cell
现在是时候设置表格单元格的文本了
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{ static NSString *CellIdentifier = @"Cell";
{static NSString * CellIdentifier = @“Cell”;
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
// Configure the cell...
//setting the text of the cell as per Mutable array
if (indexPath.row < [arr count]) {
cell.textLabel.text = [arr objectAtIndex:indexPath.row];
}
//setting the text of the extra cell
if (indexPath.row == dataRows) {
cell.textLabel.text = @"more cells";
}
return cell;
}
}
now on the hit of the more cells cell you want extra cells right so just add your code inside the
现在,在更多单元格单元格的命中,您需要额外的单元格,所以只需添加您的代码
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
method, means you have to do something like this
方法,意味着你必须做这样的事情
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { if(indexPath.row == dataRows) { //code for exra cells please } }
Run your app to check this code out.
运行您的应用以检查此代码。